@@ -390,6 +390,7 @@ def parse_executed_tests(self, output):
390390
391391 def check_executed_tests (self , output , tests , skipped = (), failed = (),
392392 env_changed = (), omitted = (),
393+ rerun = (),
393394 randomize = False , interrupted = False ,
394395 fail_env_changed = False ):
395396 if isinstance (tests , str ):
@@ -402,6 +403,8 @@ def check_executed_tests(self, output, tests, skipped=(), failed=(),
402403 env_changed = [env_changed ]
403404 if isinstance (omitted , str ):
404405 omitted = [omitted ]
406+ if isinstance (rerun , str ):
407+ rerun = [rerun ]
405408
406409 executed = self .parse_executed_tests (output )
407410 if randomize :
@@ -436,6 +439,14 @@ def list_regex(line_format, tests):
436439 regex = list_regex ('%s test%s omitted' , omitted )
437440 self .check_line (output , regex )
438441
442+ if rerun :
443+ regex = list_regex ('%s re-run test%s' , rerun )
444+ self .check_line (output , regex )
445+ self .check_line (output , "Re-running failed tests in verbose mode" )
446+ for name in rerun :
447+ regex = "Re-running test %r in verbose mode" % name
448+ self .check_line (output , regex )
449+
439450 good = (len (tests ) - len (skipped ) - len (failed )
440451 - len (omitted ) - len (env_changed ))
441452 if good :
@@ -447,14 +458,19 @@ def list_regex(line_format, tests):
447458 if interrupted :
448459 self .check_line (output , 'Test suite interrupted by signal SIGINT.' )
449460
461+ result = []
450462 if failed :
451- result = 'FAILURE'
452- elif interrupted :
453- result = 'INTERRUPTED'
463+ result .append ('FAILURE' )
454464 elif fail_env_changed and env_changed :
455- result = 'ENV CHANGED'
456- else :
457- result = 'SUCCESS'
465+ result .append ('ENV CHANGED' )
466+ if interrupted :
467+ result .append ('INTERRUPTED' )
468+ if not result :
469+ result .append ('SUCCESS' )
470+ result = ', ' .join (result )
471+ if rerun :
472+ self .check_line (output , 'Tests result: %s' % result )
473+ result = 'FAILURE then %s' % result
458474 self .check_line (output , 'Tests result: %s' % result )
459475
460476 def parse_random_seed (self , output ):
@@ -948,6 +964,21 @@ def test_env_changed(self):
948964 self .check_executed_tests (output , [testname ], env_changed = testname ,
949965 fail_env_changed = True )
950966
967+ def test_rerun_fail (self ):
968+ code = textwrap .dedent ("""
969+ import unittest
970+
971+ class Tests(unittest.TestCase):
972+ def test_bug(self):
973+ # test always fail
974+ self.fail("bug")
975+ """ )
976+ testname = self .create_test (code = code )
977+
978+ output = self .run_tests ("-w" , testname , exitcode = 2 )
979+ self .check_executed_tests (output , [testname ],
980+ failed = testname , rerun = testname )
981+
951982
952983if __name__ == '__main__' :
953984 unittest .main ()
0 commit comments