@@ -92,6 +92,7 @@ def parse_executed_tests(self, output):
92
92
93
93
def check_executed_tests (self , output , tests , skipped = (), failed = (),
94
94
env_changed = (), omitted = (),
95
+ rerun = (),
95
96
randomize = False , interrupted = False ,
96
97
fail_env_changed = False ):
97
98
if isinstance (tests , str ):
@@ -104,6 +105,8 @@ def check_executed_tests(self, output, tests, skipped=(), failed=(),
104
105
env_changed = [env_changed ]
105
106
if isinstance (omitted , str ):
106
107
omitted = [omitted ]
108
+ if isinstance (rerun , str ):
109
+ rerun = [rerun ]
107
110
108
111
executed = self .parse_executed_tests (output )
109
112
if randomize :
@@ -138,6 +141,14 @@ def list_regex(line_format, tests):
138
141
regex = list_regex ('%s test%s omitted' , omitted )
139
142
self .check_line (output , regex )
140
143
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
+
141
152
good = (len (tests ) - len (skipped ) - len (failed )
142
153
- len (omitted ) - len (env_changed ))
143
154
if good :
@@ -149,14 +160,19 @@ def list_regex(line_format, tests):
149
160
if interrupted :
150
161
self .check_line (output , 'Test suite interrupted by signal SIGINT.' )
151
162
163
+ result = []
152
164
if failed :
153
- result = 'FAILURE'
154
- elif interrupted :
155
- result = 'INTERRUPTED'
165
+ result .append ('FAILURE' )
156
166
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
160
176
self .check_line (output , 'Tests result: %s' % result )
161
177
162
178
def parse_random_seed (self , output ):
@@ -648,6 +664,24 @@ def test_main():
648
664
self .check_executed_tests (output , [testname ], env_changed = testname ,
649
665
fail_env_changed = True )
650
666
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
+
651
685
652
686
def test_main ():
653
687
support .run_unittest (ProgramsTestCase , ArgsTestCase )
0 commit comments