Skip to content

Commit 58ed730

Browse files
authored
bpo-33873: Fix bug in runtest.py and add checks for invalid -R parameters (GH-7735)
Fix bug in `Lib/test/libregrtest/runtest.py` that makes running tests an extra time than the specified number of runs. Add check for invalid --huntrleaks/-R parameters.
1 parent 866c168 commit 58ed730

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Lib/test/libregrtest/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,15 @@ def main(self, tests=None, **kwargs):
533533
def _main(self, tests, kwargs):
534534
self.ns = self.parse_args(kwargs)
535535

536+
if self.ns.huntrleaks:
537+
warmup, repetitions, _ = self.ns.huntrleaks
538+
if warmup < 1 or repetitions < 1:
539+
msg = ("Invalid values for the --huntrleaks/-R parameters. The "
540+
"number of warmups and repetitions must be at least 1 "
541+
"each (1:1).")
542+
print(msg, file=sys.stderr, flush=True)
543+
sys.exit(2)
544+
536545
if self.ns.slaveargs is not None:
537546
from test.libregrtest.runtest_mp import run_tests_slave
538547
run_tests_slave(self.ns.slaveargs)

Lib/test/libregrtest/runtest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,10 @@ def test_runner():
173173
if loader.errors:
174174
raise Exception("errors while loading tests")
175175
support.run_unittest(tests)
176-
test_runner()
177176
if ns.huntrleaks:
178177
refleak = dash_R(the_module, test, test_runner, ns.huntrleaks)
178+
else:
179+
test_runner()
179180
test_time = time.time() - start_time
180181
post_test_cleanup()
181182
except support.ResourceDenied as msg:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a bug in ``regrtest`` that caused an extra test to run if
2+
--huntrleaks/-R was used. Exit with error in case that invalid
3+
parameters are specified to --huntrleaks/-R (at least one warmup
4+
run and one repetition must be used).

0 commit comments

Comments
 (0)