Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Don't use None for randomize
  • Loading branch information
vstinner committed Sep 8, 2025
commit 754a8c4d8c18b9b122317652e04bf87499978826
11 changes: 6 additions & 5 deletions Lib/test/libregrtest/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __init__(self, **kwargs) -> None:
self.list_cases = False
self.list_tests = False
self.single = False
self.randomize = None
self.randomize = False
self.fromfile = None
self.fail_env_changed = False
self.use_resources: list[str] = []
Expand Down Expand Up @@ -271,7 +271,7 @@ def _create_parser():
group = parser.add_argument_group('Selecting tests')
group.add_argument('-r', '--randomize', action='store_true',
help='randomize test execution order.' + more_details)
group.add_argument('--no-randomize', dest='randomize', action='store_false',
group.add_argument('--no-randomize', dest='no_randomize', action='store_true',
help='do not randomize test execution order, even if '
'it would be implied by another option')
group.add_argument('--prioritize', metavar='TEST1,TEST2,...',
Expand Down Expand Up @@ -459,8 +459,7 @@ def _parse_args(args, **kwargs):
# -j0 --randomize --fail-env-changed --rerun --slowest --verbose3
if ns.use_mp is None:
ns.use_mp = 0
if ns.randomize is None:
ns.randomize = True
ns.randomize = True
ns.fail_env_changed = True
if ns.python is None:
ns.rerun = True
Expand Down Expand Up @@ -541,8 +540,10 @@ def _parse_args(args, **kwargs):
ns.use_resources.remove(r)
elif r not in ns.use_resources:
ns.use_resources.append(r)
if ns.random_seed is not None and ns.randomize is None:
if ns.random_seed is not None:
ns.randomize = True
if ns.no_randomize:
ns.randomize = False
if ns.verbose:
ns.header = True

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False):
self._tmp_dir: StrPath | None = ns.tempdir

# Randomize
self.randomize: bool = bool(ns.randomize)
self.randomize: bool = ns.randomize
if ('SOURCE_DATE_EPOCH' in os.environ
# don't use the variable if empty
and os.environ['SOURCE_DATE_EPOCH']
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_randomize(self):

def test_no_randomize(self):
ns = self.parse_args([])
self.assertIsNone(ns.randomize)
self.assertIs(ns.randomize, False)

ns = self.parse_args(["--randomize"])
self.assertIs(ns.randomize, True)
Expand All @@ -196,7 +196,7 @@ def test_no_randomize(self):
self.assertIs(ns.randomize, False)

ns = self.parse_args(["--no-randomize", "--randomize"])
self.assertIs(ns.randomize, True)
self.assertIs(ns.randomize, False)

def test_randseed(self):
ns = self.parse_args(['--randseed', '12345'])
Expand Down Expand Up @@ -452,6 +452,7 @@ def check_ci_mode(self, args, use_resources, *, rerun=True, randomize=True):
regrtest = self.create_regrtest(args)
self.assertEqual(regrtest.num_workers, -1)
self.assertEqual(regrtest.want_rerun, rerun)
self.assertEqual(regrtest.fail_rerun, False)
self.assertEqual(regrtest.randomize, randomize)
self.assertIsInstance(regrtest.random_seed, int)
self.assertTrue(regrtest.fail_env_changed)
Expand Down
Loading