Skip to content

Commit b64cace

Browse files
committed
Revert changes to default args; add a --no-randomize option instead
1 parent f69095c commit b64cace

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

Android/android.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,8 +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+
# Randomization is disabled because order-dependent failures are
741+
# much less likely to pass on a rerun in single-process mode.
740742
launcher_args = ["--managed", "maxVersion", "-v"]
741-
test_args = ["--fast-ci", "--single-process"]
743+
test_args = ["--fast-ci", "--single-process", "--no-randomize"]
742744
run(
743745
["./android.py", "test", *launcher_args, "--", *test_args],
744746
cwd=temp_dir

Lib/test/libregrtest/cmdline.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __init__(self, **kwargs) -> None:
155155
self.list_cases = False
156156
self.list_tests = False
157157
self.single = False
158-
self.randomize = False
158+
self.randomize = None
159159
self.fromfile = None
160160
self.fail_env_changed = False
161161
self.use_resources: list[str] = []
@@ -271,6 +271,9 @@ def _create_parser():
271271
group = parser.add_argument_group('Selecting tests')
272272
group.add_argument('-r', '--randomize', action='store_true',
273273
help='randomize test execution order.' + more_details)
274+
group.add_argument('--no-randomize', dest='randomize', action='store_false',
275+
help='do not randomize test execution order, even if '
276+
'it would be implied by another option')
274277
group.add_argument('--prioritize', metavar='TEST1,TEST2,...',
275278
action='append', type=priority_list,
276279
help='select these tests first, even if the order is'
@@ -453,13 +456,14 @@ def _parse_args(args, **kwargs):
453456
# Continuous Integration (CI): common options for fast/slow CI modes
454457
if ns.slow_ci or ns.fast_ci:
455458
# Similar to options:
456-
# -j0 --fail-env-changed --rerun --fail-rerun --slowest --verbose3
459+
# -j0 --randomize --fail-env-changed --rerun --slowest --verbose3
457460
if ns.use_mp is None:
458461
ns.use_mp = 0
462+
if ns.randomize is None:
463+
ns.randomize = True
459464
ns.fail_env_changed = True
460465
if ns.python is None:
461466
ns.rerun = True
462-
ns.fail_rerun = True
463467
ns.print_slow = True
464468
ns.verbose3 = True
465469
else:
@@ -537,7 +541,7 @@ def _parse_args(args, **kwargs):
537541
ns.use_resources.remove(r)
538542
elif r not in ns.use_resources:
539543
ns.use_resources.append(r)
540-
if ns.random_seed is not None:
544+
if ns.random_seed is not None and ns.randomize is None:
541545
ns.randomize = True
542546
if ns.verbose:
543547
ns.header = True

Lib/test/libregrtest/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False):
128128
self._tmp_dir: StrPath | None = ns.tempdir
129129

130130
# Randomize
131-
self.randomize: bool = ns.randomize
131+
self.randomize: bool = bool(ns.randomize)
132132
if ('SOURCE_DATE_EPOCH' in os.environ
133133
# don't use the variable if empty
134134
and os.environ['SOURCE_DATE_EPOCH']

Lib/test/test_regrtest.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,33 @@ def test_randomize(self):
182182
self.assertTrue(regrtest.randomize)
183183
self.assertIsInstance(regrtest.random_seed, int)
184184

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

208+
ns = self.parse_args(['--randseed', '12345', '--no-randomize'])
209+
self.assertEqual(ns.random_seed, 12345)
210+
self.assertFalse(ns.randomize)
211+
192212
def test_fromfile(self):
193213
for opt in '-f', '--fromfile':
194214
with self.subTest(opt=opt):
@@ -428,11 +448,11 @@ def create_regrtest(self, args):
428448

429449
return regrtest
430450

431-
def check_ci_mode(self, args, use_resources, rerun=True):
451+
def check_ci_mode(self, args, use_resources, *, rerun=True, randomize=True):
432452
regrtest = self.create_regrtest(args)
433453
self.assertEqual(regrtest.num_workers, -1)
434454
self.assertEqual(regrtest.want_rerun, rerun)
435-
self.assertEqual(regrtest.fail_rerun, rerun)
455+
self.assertEqual(regrtest.randomize, randomize)
436456
self.assertIsInstance(regrtest.random_seed, int)
437457
self.assertTrue(regrtest.fail_env_changed)
438458
self.assertTrue(regrtest.print_slowest)
@@ -469,6 +489,15 @@ def test_slow_ci(self):
469489
regrtest = self.check_ci_mode(args, use_resources)
470490
self.assertEqual(regrtest.timeout, 20 * 60)
471491

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

0 commit comments

Comments
 (0)