Skip to content

[2.7] bpo-33718: regrtest: use "xxx then yyy" result if re-run (GH-7521) #7562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Lib/test/regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
resource_denieds = []
environment_changed = []
rerun = []
first_result = None
interrupted = False

if findleaks:
Expand Down Expand Up @@ -907,7 +908,10 @@ def get_tests_result():
if not result:
result.append("SUCCESS")

return ', '.join(result)
result = ', '.join(result)
if first_result:
result = '%s then %s' % (first_result, result)
return result


def display_result():
Expand Down Expand Up @@ -974,6 +978,8 @@ def display_result():
display_result()

if verbose2 and bad:
first_result = get_tests_result()

print
print "Re-running failed tests in verbose mode"
rerun = bad[:]
Expand Down
46 changes: 40 additions & 6 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def parse_executed_tests(self, output):

def check_executed_tests(self, output, tests, skipped=(), failed=(),
env_changed=(), omitted=(),
rerun=(),
randomize=False, interrupted=False,
fail_env_changed=False):
if isinstance(tests, str):
Expand All @@ -104,6 +105,8 @@ def check_executed_tests(self, output, tests, skipped=(), failed=(),
env_changed = [env_changed]
if isinstance(omitted, str):
omitted = [omitted]
if isinstance(rerun, str):
rerun = [rerun]

executed = self.parse_executed_tests(output)
if randomize:
Expand Down Expand Up @@ -138,6 +141,14 @@ def list_regex(line_format, tests):
regex = list_regex('%s test%s omitted', omitted)
self.check_line(output, regex)

if rerun:
regex = list_regex('%s re-run test%s', rerun)
self.check_line(output, regex)
self.check_line(output, "Re-running failed tests in verbose mode")
for name in rerun:
regex = "Re-running test %r in verbose mode" % name
self.check_line(output, regex)

good = (len(tests) - len(skipped) - len(failed)
- len(omitted) - len(env_changed))
if good:
Expand All @@ -149,14 +160,19 @@ def list_regex(line_format, tests):
if interrupted:
self.check_line(output, 'Test suite interrupted by signal SIGINT.')

result = []
if failed:
result = 'FAILURE'
elif interrupted:
result = 'INTERRUPTED'
result.append('FAILURE')
elif fail_env_changed and env_changed:
result = 'ENV CHANGED'
else:
result = 'SUCCESS'
result.append('ENV CHANGED')
if interrupted:
result.append('INTERRUPTED')
if not result:
result.append('SUCCESS')
result = ', '.join(result)
if rerun:
self.check_line(output, 'Tests result: %s' % result)
result = 'FAILURE then %s' % result
self.check_line(output, 'Tests result: %s' % result)

def parse_random_seed(self, output):
Expand Down Expand Up @@ -648,6 +664,24 @@ def test_main():
self.check_executed_tests(output, [testname], env_changed=testname,
fail_env_changed=True)

def test_rerun_fail(self):
code = textwrap.dedent("""
import unittest

class Tests(unittest.TestCase):
def test_bug(self):
# test always fail
self.fail("bug")

def test_main():
support.run_unittest(Tests)
""")
testname = self.create_test(code=code)

output = self.run_tests("-w", testname, exitcode=2)
self.check_executed_tests(output, [testname],
failed=testname, rerun=testname)


def test_main():
support.run_unittest(ProgramsTestCase, ArgsTestCase)
Expand Down