Skip to content

Commit 8b85e96

Browse files
authored
Add test runner option to repeat tests. (#21749)
Helpful with running flaky tests many times.
1 parent 4dac6d6 commit 8b85e96

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

test/runner.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def error_on_legacy_suite_names(args):
267267
utils.exit_with_error('`%s` test suite has been replaced with `%s`', a, new)
268268

269269

270-
def load_test_suites(args, modules, start_at):
270+
def load_test_suites(args, modules, start_at, repeat):
271271
found_start = not start_at
272272

273273
loader = unittest.TestLoader()
@@ -296,8 +296,9 @@ def load_test_suites(args, modules, start_at):
296296
found_start = True
297297
else:
298298
continue
299-
total_tests += 1
300-
suite.addTest(test)
299+
for _x in range(repeat):
300+
total_tests += 1
301+
suite.addTest(test)
301302
suites.append((m.__name__, suite))
302303
if not found_start:
303304
utils.exit_with_error(f'unable to find --start-at test: {start_at}')
@@ -389,6 +390,8 @@ def parse_args(args):
389390
'Useful when combined with --failfast')
390391
parser.add_argument('--force64', action='store_const', const=True, default=None)
391392
parser.add_argument('--crossplatform-only', action='store_true')
393+
parser.add_argument('--repeat', type=int, default=1,
394+
help='Repeat each test N times (default: 1).')
392395
return parser.parse_args()
393396

394397

@@ -476,7 +479,7 @@ def prepend_default(arg):
476479
if os.path.exists(common.LAST_TEST):
477480
options.start_at = utils.read_file(common.LAST_TEST).strip()
478481

479-
suites, unmatched_tests = load_test_suites(tests, modules, options.start_at)
482+
suites, unmatched_tests = load_test_suites(tests, modules, options.start_at, options.repeat)
480483
if unmatched_tests:
481484
print('ERROR: could not find the following tests: ' + ' '.join(unmatched_tests))
482485
return 1

0 commit comments

Comments
 (0)