Skip to content

Commit 6f17532

Browse files
vstinnermhsmith
authored andcommitted
[3.13] gh-137242: Add a --no-randomize option, and use it in Android CI (GH-138649)
Adds a --no-randomize option to the CI runner, so that randomisation can be easily disabled for --fast-ci and --slow-ci configurations on single-threaded testing platforms like Android, iOS, and Emscripten. --------- (cherry picked from commit 01895d2) Co-authored-by: Victor Stinner <[email protected]> Co-authored-by: Malcolm Smith <[email protected]>
1 parent 9a6137a commit 6f17532

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

Android/android.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,10 @@ def ci(context):
737737
# Prove the package is self-contained by using it to run the tests.
738738
shutil.unpack_archive(package_path, temp_dir)
739739

740-
# Arguments are similar to --fast-ci, but in single-process mode.
740+
# Randomization is disabled because order-dependent failures are
741+
# much less likely to pass on a rerun in single-process mode.
741742
launcher_args = ["--managed", "maxVersion", "-v"]
742-
test_args = [
743-
"--single-process", "--fail-env-changed", "--rerun", "--slowest",
744-
"--verbose3", "-u", "all,-cpu", "--timeout=600"
745-
]
743+
test_args = ["--fast-ci", "--single-process", "--no-randomize"]
746744
run(
747745
["./android.py", "test", *launcher_args, "--", *test_args],
748746
cwd=temp_dir

Lib/test/libregrtest/cmdline.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ def _create_parser():
259259
group = parser.add_argument_group('Selecting tests')
260260
group.add_argument('-r', '--randomize', action='store_true',
261261
help='randomize test execution order.' + more_details)
262+
group.add_argument('--no-randomize', dest='no_randomize', action='store_true',
263+
help='do not randomize test execution order, even if '
264+
'it would be implied by another option')
262265
group.add_argument('-f', '--fromfile', metavar='FILE',
263266
help='read names of tests to run from a file.' +
264267
more_details)
@@ -512,6 +515,8 @@ def _parse_args(args, **kwargs):
512515
ns.use_resources.append(r)
513516
if ns.random_seed is not None:
514517
ns.randomize = True
518+
if ns.no_randomize:
519+
ns.randomize = False
515520
if ns.verbose:
516521
ns.header = True
517522

Lib/test/test_regrtest.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,33 @@ def test_randomize(self):
179179
self.assertTrue(regrtest.randomize)
180180
self.assertIsInstance(regrtest.random_seed, int)
181181

182+
def test_no_randomize(self):
183+
ns = self.parse_args([])
184+
self.assertIs(ns.randomize, False)
185+
186+
ns = self.parse_args(["--randomize"])
187+
self.assertIs(ns.randomize, True)
188+
189+
ns = self.parse_args(["--no-randomize"])
190+
self.assertIs(ns.randomize, False)
191+
192+
ns = self.parse_args(["--randomize", "--no-randomize"])
193+
self.assertIs(ns.randomize, False)
194+
195+
ns = self.parse_args(["--no-randomize", "--randomize"])
196+
self.assertIs(ns.randomize, False)
197+
182198
def test_randseed(self):
183199
ns = self.parse_args(['--randseed', '12345'])
184200
self.assertEqual(ns.random_seed, 12345)
185201
self.assertTrue(ns.randomize)
186202
self.checkError(['--randseed'], 'expected one argument')
187203
self.checkError(['--randseed', 'foo'], 'invalid int value')
188204

205+
ns = self.parse_args(['--randseed', '12345', '--no-randomize'])
206+
self.assertEqual(ns.random_seed, 12345)
207+
self.assertFalse(ns.randomize)
208+
189209
def test_fromfile(self):
190210
for opt in '-f', '--fromfile':
191211
with self.subTest(opt=opt):
@@ -425,11 +445,12 @@ def create_regrtest(self, args):
425445

426446
return regrtest
427447

428-
def check_ci_mode(self, args, use_resources, rerun=True):
448+
def check_ci_mode(self, args, use_resources, *, rerun=True, randomize=True):
429449
regrtest = self.create_regrtest(args)
430450
self.assertEqual(regrtest.num_workers, -1)
431451
self.assertEqual(regrtest.want_rerun, rerun)
432-
self.assertTrue(regrtest.randomize)
452+
self.assertEqual(regrtest.fail_rerun, False)
453+
self.assertEqual(regrtest.randomize, randomize)
433454
self.assertIsInstance(regrtest.random_seed, int)
434455
self.assertTrue(regrtest.fail_env_changed)
435456
self.assertTrue(regrtest.print_slowest)
@@ -466,6 +487,15 @@ def test_slow_ci(self):
466487
regrtest = self.check_ci_mode(args, use_resources)
467488
self.assertEqual(regrtest.timeout, 20 * 60)
468489

490+
def test_ci_no_randomize(self):
491+
all_resources = set(cmdline.ALL_RESOURCES)
492+
self.check_ci_mode(
493+
["--slow-ci", "--no-randomize"], all_resources, randomize=False
494+
)
495+
self.check_ci_mode(
496+
["--fast-ci", "--no-randomize"], all_resources - {'cpu'}, randomize=False
497+
)
498+
469499
def test_dont_add_python_opts(self):
470500
args = ['--dont-add-python-opts']
471501
ns = cmdline._parse_args(args)

0 commit comments

Comments
 (0)