Skip to content

Commit 0855b2c

Browse files
[3.12] gh-108834: Sync libregrtest with the main branch (#108966)
* 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. (cherry picked from commit 31c2945) * gh-108834: regrtest --fail-rerun exits with code 5 (#108896) When the --fail-rerun option is used and a test fails and then pass, regrtest now uses exit code 5 ("rerun) instead of 2 ("bad test"). (cherry picked from commit 1170d5a) * gh-108416: Mark slow but not CPU bound test methods with requires_resource('walltime') (GH-108480) (cherry picked from commit 1e0d627) * Manually sync Lib/test/libregrtest/ from main --------- Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent eeaae92 commit 0855b2c

29 files changed

+892
-499
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ def test_close(self):
675675

676676
close_queue(q)
677677

678+
@support.requires_resource('walltime')
678679
def test_many_processes(self):
679680
if self.TYPE == 'threads':
680681
self.skipTest('test not appropriate for {}'.format(self.TYPE))
@@ -4953,6 +4954,7 @@ def test_wait_slow(self):
49534954
def test_wait_socket_slow(self):
49544955
self.test_wait_socket(True)
49554956

4957+
@support.requires_resource('walltime')
49564958
def test_wait_timeout(self):
49574959
from multiprocessing.connection import wait
49584960

@@ -4981,6 +4983,7 @@ def signal_and_sleep(cls, sem, period):
49814983
sem.release()
49824984
time.sleep(period)
49834985

4986+
@support.requires_resource('walltime')
49844987
def test_wait_integer(self):
49854988
from multiprocessing.connection import wait
49864989

Lib/test/bisect_cmd.py

Lines changed: 4 additions & 3 deletions
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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
108108
cpu - Used for certain CPU-heavy tests.
109109
110+
walltime - Long running but not CPU-bound tests.
111+
110112
subprocess Run all tests for the subprocess module.
111113
112114
urlfetch - It is okay to download files required on testing.
@@ -129,7 +131,7 @@
129131

130132

131133
ALL_RESOURCES = ('audio', 'curses', 'largefile', 'network',
132-
'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui')
134+
'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui', 'walltime')
133135

134136
# Other resources excluded from --use=all:
135137
#
@@ -156,7 +158,7 @@ def __init__(self, **kwargs) -> None:
156158
self.coverdir = 'coverage'
157159
self.runleaks = False
158160
self.huntrleaks = False
159-
self.verbose2 = False
161+
self.rerun = False
160162
self.verbose3 = False
161163
self.print_slow = False
162164
self.random_seed = None
@@ -213,8 +215,10 @@ def _create_parser():
213215
group = parser.add_argument_group('Verbosity')
214216
group.add_argument('-v', '--verbose', action='count',
215217
help='run tests in verbose mode with output to stdout')
216-
group.add_argument('-w', '--verbose2', action='store_true',
218+
group.add_argument('-w', '--rerun', action='store_true',
217219
help='re-run failed tests in verbose mode')
220+
group.add_argument('--verbose2', action='store_true', dest='rerun',
221+
help='deprecated alias to --rerun')
218222
group.add_argument('-W', '--verbose3', action='store_true',
219223
help='display test output on failure')
220224
group.add_argument('-q', '--quiet', action='store_true',
@@ -309,6 +313,9 @@ def _create_parser():
309313
group.add_argument('--fail-env-changed', action='store_true',
310314
help='if a test file alters the environment, mark '
311315
'the test as failed')
316+
group.add_argument('--fail-rerun', action='store_true',
317+
help='if a test failed and then passed when re-run, '
318+
'mark the tests as failed')
312319

313320
group.add_argument('--junit-xml', dest='xmlpath', metavar='FILENAME',
314321
help='writes JUnit-style XML results to the specified '
@@ -380,7 +387,7 @@ def _parse_args(args, **kwargs):
380387
ns.python = shlex.split(ns.python)
381388
if ns.failfast and not (ns.verbose or ns.verbose3):
382389
parser.error("-G/--failfast needs either -v or -W")
383-
if ns.pgo and (ns.verbose or ns.verbose2 or ns.verbose3):
390+
if ns.pgo and (ns.verbose or ns.rerun or ns.verbose3):
384391
parser.error("--pgo/-v don't go together!")
385392
if ns.pgo_extended:
386393
ns.pgo = True # pgo_extended implies pgo

0 commit comments

Comments
 (0)