@@ -389,6 +389,7 @@ def parse_executed_tests(self, output):
389389
390390 def check_executed_tests (self , output , tests , skipped = (), failed = (),
391391 env_changed = (), omitted = (),
392+ rerun = (),
392393 randomize = False , interrupted = False ,
393394 fail_env_changed = False ):
394395 if isinstance (tests , str ):
@@ -401,6 +402,8 @@ def check_executed_tests(self, output, tests, skipped=(), failed=(),
401402 env_changed = [env_changed ]
402403 if isinstance (omitted , str ):
403404 omitted = [omitted ]
405+ if isinstance (rerun , str ):
406+ rerun = [rerun ]
404407
405408 executed = self .parse_executed_tests (output )
406409 if randomize :
@@ -435,6 +438,14 @@ def list_regex(line_format, tests):
435438 regex = list_regex ('%s test%s omitted' , omitted )
436439 self .check_line (output , regex )
437440
441+ if rerun :
442+ regex = list_regex ('%s re-run test%s' , rerun )
443+ self .check_line (output , regex )
444+ self .check_line (output , "Re-running failed tests in verbose mode" )
445+ for name in rerun :
446+ regex = "Re-running test %r in verbose mode" % name
447+ self .check_line (output , regex )
448+
438449 good = (len (tests ) - len (skipped ) - len (failed )
439450 - len (omitted ) - len (env_changed ))
440451 if good :
@@ -446,14 +457,19 @@ def list_regex(line_format, tests):
446457 if interrupted :
447458 self .check_line (output , 'Test suite interrupted by signal SIGINT.' )
448459
460+ result = []
449461 if failed :
450- result = 'FAILURE'
451- elif interrupted :
452- result = 'INTERRUPTED'
462+ result .append ('FAILURE' )
453463 elif fail_env_changed and env_changed :
454- result = 'ENV CHANGED'
455- else :
456- result = 'SUCCESS'
464+ result .append ('ENV CHANGED' )
465+ if interrupted :
466+ result .append ('INTERRUPTED' )
467+ if not result :
468+ result .append ('SUCCESS' )
469+ result = ', ' .join (result )
470+ if rerun :
471+ self .check_line (output , 'Tests result: %s' % result )
472+ result = 'FAILURE then %s' % result
457473 self .check_line (output , 'Tests result: %s' % result )
458474
459475 def parse_random_seed (self , output ):
@@ -952,6 +968,21 @@ def test_env_changed(self):
952968 self .check_executed_tests (output , [testname ], env_changed = testname ,
953969 fail_env_changed = True )
954970
971+ def test_rerun_fail (self ):
972+ code = textwrap .dedent ("""
973+ import unittest
974+
975+ class Tests(unittest.TestCase):
976+ def test_bug(self):
977+ # test always fail
978+ self.fail("bug")
979+ """ )
980+ testname = self .create_test (code = code )
981+
982+ output = self .run_tests ("-w" , testname , exitcode = 2 )
983+ self .check_executed_tests (output , [testname ],
984+ failed = testname , rerun = testname )
985+
955986
956987if __name__ == '__main__' :
957988 unittest .main ()
0 commit comments