Skip to content

Commit b4f8bc5

Browse files
authored
bpo-33718: regrtest: use "xxx then yyy" result if re-run (GH-7521) (GH-7562)
If tests are re-run, use "xxx then yyy" result format (ex: "FAILURE then SUCCESS") to show that some failing tests have been re-run. Add also test_regrtest.test_rerun_fail() test. (cherry picked from commit c45fc76)
1 parent 4e6bd24 commit b4f8bc5

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

Lib/test/regrtest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
530530
resource_denieds = []
531531
environment_changed = []
532532
rerun = []
533+
first_result = None
533534
interrupted = False
534535

535536
if findleaks:
@@ -907,7 +908,10 @@ def get_tests_result():
907908
if not result:
908909
result.append("SUCCESS")
909910

910-
return ', '.join(result)
911+
result = ', '.join(result)
912+
if first_result:
913+
result = '%s then %s' % (first_result, result)
914+
return result
911915

912916

913917
def display_result():
@@ -974,6 +978,8 @@ def display_result():
974978
display_result()
975979

976980
if verbose2 and bad:
981+
first_result = get_tests_result()
982+
977983
print
978984
print "Re-running failed tests in verbose mode"
979985
rerun = bad[:]

Lib/test/test_regrtest.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def parse_executed_tests(self, output):
9292

9393
def check_executed_tests(self, output, tests, skipped=(), failed=(),
9494
env_changed=(), omitted=(),
95+
rerun=(),
9596
randomize=False, interrupted=False,
9697
fail_env_changed=False):
9798
if isinstance(tests, str):
@@ -104,6 +105,8 @@ def check_executed_tests(self, output, tests, skipped=(), failed=(),
104105
env_changed = [env_changed]
105106
if isinstance(omitted, str):
106107
omitted = [omitted]
108+
if isinstance(rerun, str):
109+
rerun = [rerun]
107110

108111
executed = self.parse_executed_tests(output)
109112
if randomize:
@@ -138,6 +141,14 @@ def list_regex(line_format, tests):
138141
regex = list_regex('%s test%s omitted', omitted)
139142
self.check_line(output, regex)
140143

144+
if rerun:
145+
regex = list_regex('%s re-run test%s', rerun)
146+
self.check_line(output, regex)
147+
self.check_line(output, "Re-running failed tests in verbose mode")
148+
for name in rerun:
149+
regex = "Re-running test %r in verbose mode" % name
150+
self.check_line(output, regex)
151+
141152
good = (len(tests) - len(skipped) - len(failed)
142153
- len(omitted) - len(env_changed))
143154
if good:
@@ -149,14 +160,19 @@ def list_regex(line_format, tests):
149160
if interrupted:
150161
self.check_line(output, 'Test suite interrupted by signal SIGINT.')
151162

163+
result = []
152164
if failed:
153-
result = 'FAILURE'
154-
elif interrupted:
155-
result = 'INTERRUPTED'
165+
result.append('FAILURE')
156166
elif fail_env_changed and env_changed:
157-
result = 'ENV CHANGED'
158-
else:
159-
result = 'SUCCESS'
167+
result.append('ENV CHANGED')
168+
if interrupted:
169+
result.append('INTERRUPTED')
170+
if not result:
171+
result.append('SUCCESS')
172+
result = ', '.join(result)
173+
if rerun:
174+
self.check_line(output, 'Tests result: %s' % result)
175+
result = 'FAILURE then %s' % result
160176
self.check_line(output, 'Tests result: %s' % result)
161177

162178
def parse_random_seed(self, output):
@@ -648,6 +664,24 @@ def test_main():
648664
self.check_executed_tests(output, [testname], env_changed=testname,
649665
fail_env_changed=True)
650666

667+
def test_rerun_fail(self):
668+
code = textwrap.dedent("""
669+
import unittest
670+
671+
class Tests(unittest.TestCase):
672+
def test_bug(self):
673+
# test always fail
674+
self.fail("bug")
675+
676+
def test_main():
677+
support.run_unittest(Tests)
678+
""")
679+
testname = self.create_test(code=code)
680+
681+
output = self.run_tests("-w", testname, exitcode=2)
682+
self.check_executed_tests(output, [testname],
683+
failed=testname, rerun=testname)
684+
651685

652686
def test_main():
653687
support.run_unittest(ProgramsTestCase, ArgsTestCase)

0 commit comments

Comments
 (0)