Skip to content

Commit 31c2945

Browse files
authored
gh-108834: regrtest reruns failed tests in subprocesses (#108839)
When using --rerun option, regrtest now re-runs failed tests in verbose mode in fresh worker processes to have more deterministic behavior. So it can write its final report even if a test killed a worker progress. Add --fail-rerun option to regrtest: exit with non-zero exit code if a test failed pass passed when re-run in verbose mode (in a fresh process). That's now more useful since tests can pass when re-run in a fresh worker progress, whereas they failed when run after other tests when tests are run sequentially. Rename --verbose2 option (-w) to --rerun. Keep --verbose2 as a deprecated alias. Changes: * Fix and enhance statistics in regrtest summary. Add "(filtered)" when --match and/or --ignore options are used. * Add RunTests class. * Add TestResult.get_rerun_match_tests() method * Rewrite code to serialize/deserialize worker arguments as JSON using a new WorkerJob class. * Fix stats when a test is run with --forever --rerun. * If failed test names cannot be parsed, log a warning and don't filter tests. * test_regrtest.test_rerun_success() now uses a marker file, since the test is re-run in a separated process. * Add tests on normalize_test_name() function. * Add test_success() and test_skip() tests to test_regrtest.
1 parent c2ec174 commit 31c2945

12 files changed

+821
-480
lines changed

Lib/test/bisect_cmd.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,10 @@ def parse_args():
109109

110110
def main():
111111
args = parse_args()
112-
if '-w' in args.test_args or '--verbose2' in args.test_args:
113-
print("WARNING: -w/--verbose2 option should not be used to bisect!")
114-
print()
112+
for opt in ('-w', '--rerun', '--verbose2'):
113+
if opt in args.test_args:
114+
print(f"WARNING: {opt} option should not be used to bisect!")
115+
print()
115116

116117
if args.input:
117118
with open(args.input) as fp:

Lib/test/libregrtest/cmdline.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def __init__(self, **kwargs) -> None:
156156
self.coverdir = 'coverage'
157157
self.runleaks = False
158158
self.huntrleaks = False
159-
self.verbose2 = False
159+
self.rerun = False
160160
self.verbose3 = False
161161
self.print_slow = False
162162
self.random_seed = None
@@ -213,8 +213,10 @@ def _create_parser():
213213
group = parser.add_argument_group('Verbosity')
214214
group.add_argument('-v', '--verbose', action='count',
215215
help='run tests in verbose mode with output to stdout')
216-
group.add_argument('-w', '--verbose2', action='store_true',
216+
group.add_argument('-w', '--rerun', action='store_true',
217217
help='re-run failed tests in verbose mode')
218+
group.add_argument('--verbose2', action='store_true', dest='rerun',
219+
help='deprecated alias to --rerun')
218220
group.add_argument('-W', '--verbose3', action='store_true',
219221
help='display test output on failure')
220222
group.add_argument('-q', '--quiet', action='store_true',
@@ -309,6 +311,9 @@ def _create_parser():
309311
group.add_argument('--fail-env-changed', action='store_true',
310312
help='if a test file alters the environment, mark '
311313
'the test as failed')
314+
group.add_argument('--fail-rerun', action='store_true',
315+
help='if a test failed and then passed when re-run, '
316+
'mark the tests as failed')
312317

313318
group.add_argument('--junit-xml', dest='xmlpath', metavar='FILENAME',
314319
help='writes JUnit-style XML results to the specified '
@@ -380,7 +385,7 @@ def _parse_args(args, **kwargs):
380385
ns.python = shlex.split(ns.python)
381386
if ns.failfast and not (ns.verbose or ns.verbose3):
382387
parser.error("-G/--failfast needs either -v or -W")
383-
if ns.pgo and (ns.verbose or ns.verbose2 or ns.verbose3):
388+
if ns.pgo and (ns.verbose or ns.rerun or ns.verbose3):
384389
parser.error("--pgo/-v don't go together!")
385390
if ns.pgo_extended:
386391
ns.pgo = True # pgo_extended implies pgo

0 commit comments

Comments
 (0)