8000 gh-119727: Add --sequentially option to regrtest · vstinner/cpython@ef0522a · GitHub
[go: up one dir, main page]

Skip to content

Commit ef0522a

Browse files
committed
pythongh-119727: Add --sequentially option to regrtest
1 parent 1f481fd commit ef0522a

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

Lib/test/libregrtest/cmdline.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff 8000 line numberDiff line change
@@ -174,6 +174,7 @@ def __init__(self, **kwargs) -> None:
174174
self.tempdir = None
175175
self._add_python_opts = True
176176
self.xmlpath = None
177+
self.sequentially = False
177178

178179
super().__init__(**kwargs)
179180

@@ -307,6 +308,10 @@ def _create_parser():
307308
group.add_argument('-j', '--multiprocess', metavar='PROCESSES',
308309
dest='use_mp', type=int,
309310
help='run PROCESSES processes at once')
311+
group.add_argument('--sequentially', action='store_true',
312+
help='always run all tests sequentially, '
313+
'ignore -jN option, '
314+
'and failed tests are also rerun sequentially')
310315
group.add_argument('-T', '--coverage', action='store_true',
311316
dest='trace',
312317
help='turn on code coverage tracing using the trace '

Lib/test/libregrtest/main.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False):
8989
self.cmdline_args: TestList = ns.args
9090

9191
# Workers
92-
if ns.use_mp is None:
92+
self.sequentially: bool = ns.sequentially
93+
if self.sequentially:
94+
num_workers = 0 # run sequentially
95+
elif ns.use_mp is None:
9396
num_workers = 0 # run sequentially
9497
elif ns.use_mp <= 0:
9598
num_workers = -1 # use the number of CPUs
@@ -236,7 +239,7 @@ def list_tests(tests: TestTuple):
236239

237240
def _rerun_failed_tests(self, runtests: RunTests):
238241
# Configure the runner to re-run tests
239-
if self.num_workers == 0:
242+
if self.num_workers == 0 and not self.sequentially:
240243
# Always run tests in fresh processes to have more deterministic
241244
# initial state. Don't re-run tests in parallel but limit to a
242245
# single worker process to have side effects (on the system load
@@ -246,7 +249,6 @@ def _rerun_failed_tests(self, runtests: RunTests):
246249
tests, match_tests_dict = self.results.prepare_rerun()
247250

248251
# Re-run failed tests
249-
self.log(f"Re-running {len(tests)} failed tests in verbose mode in subprocesses")
250252
runtests = runtests.copy(
251253
tests=tests,
252254
rerun=True,
@@ -256,7 +258,15 @@ def _rerun_failed_tests(self, runtests: RunTests):
256258
match_tests_dict=match_tests_dict,
257259
output_on_failure=False)
258260
self.logger.set_tests(runtests)
259-
self._run_tests_mp(runtests, self.num_workers)
261+
262+
msg = f"Re-running {len(tests)} failed tests in verbose mode"
263+
if not self.sequentially:
264+
msg = f"{msg} in subprocesses"
265+
self.log(msg)
266+
self._run_tests_mp(runtests, self.num_workers)
267+
else:
268+
self.log(msg)
269+
self.run_tests_sequentially(runtests)
260270
return runtests
261271

262272
def rerun_failed_tests(self, runtests: RunTests):
@@ -599,7 +609,7 @@ def _add_cross_compile_opts(self, regrtest_opts):
599609
keep_environ = True
600610

601611
if cross_compile and hostrunner:
602-
if self.num_workers == 0:
612+
if self.num_workers == 0 and not self.sequentially:
603613
# For now use only two cores for cross-compiled builds;
604614
# hostrunner can be expensive.
605615
regrtest_opts.extend(['-j', '2'])

Lib/test/test_regrtest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,13 @@ def test_verbose3_huntrleaks(self):
473473
self.assertEqual(regrtest.hunt_refleak.runs, 10)
474474
self.assertFalse(regrtest.output_on_failure)
475475

476+
def test_sequentially(self):
477+
args = ['-j2', '--sequentially']
478+
with support.captured_stderr():
479+
regrtest = self.create_regrtest(args)
480+
self.assertEqual(regrtest.num_workers, 0)
481+
self.assertTrue(regrtest.sequentially)
482+
476483

477484
@dataclasses.dataclass(slots=True)
478485
class Rerun:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add ``--sequentially`` command line option to Python test runner (regrtest).
2+
Patch by Victor Stinner.

0 commit comments

Comments
 (0)
0