summaryrefslogtreecommitdiffstats
path: root/Lib/test/libregrtest
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-09-12 03:35:08 (GMT)
committerGitHub <noreply@github.com>2023-09-12 03:35:08 (GMT)
commita84cb74d42a28cf8e72ed7b5d9412fc13d18c817 (patch)
treea3d007a2718db76fc6cca4ed21c00ae84c1b440c /Lib/test/libregrtest
parent4e77645986fd27beaf25779426ae8580009fae33 (diff)
downloadcpython-a84cb74d42a28cf8e72ed7b5d9412fc13d18c817.zip
cpython-a84cb74d42a28cf8e72ed7b5d9412fc13d18c817.tar.gz
cpython-a84cb74d42a28cf8e72ed7b5d9412fc13d18c817.tar.bz2
gh-109276: libregrtest calls random.seed() before each test (#109279)
libregrtest now calls random.seed() before running each test file when -r/--randomize command line option is used. Moreover, it's also called in worker processes. It should help to make tests more deterministic. Previously, it was only called once in the main process before running all test files and it was not called in worker processes. * Convert some f-strings to regular strings in test_regrtest when f-string is not needed. * Remove unused all_methods variable from test_regrtest. * Add RunTests members are now mandatory.
Diffstat (limited to 'Lib/test/libregrtest')
-rw-r--r--Lib/test/libregrtest/main.py13
-rw-r--r--Lib/test/libregrtest/runtests.py44
-rw-r--r--Lib/test/libregrtest/setup.py4
3 files changed, 38 insertions, 23 deletions
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
index 2c0a6c2..f52deac 100644
--- a/Lib/test/libregrtest/main.py
+++ b/Lib/test/libregrtest/main.py
@@ -112,8 +112,11 @@ class Regrtest:
self.junit_filename: StrPath | None = ns.xmlpath
self.memory_limit: str | None = ns.memlimit
self.gc_threshold: int | None = ns.threshold
- self.use_resources: list[str] = ns.use_resources
- self.python_cmd: list[str] | None = ns.python
+ self.use_resources: tuple[str] = tuple(ns.use_resources)
+ if ns.python:
+ self.python_cmd: tuple[str] = tuple(ns.python)
+ else:
+ self.python_cmd = None
self.coverage: bool = ns.trace
self.coverage_dir: StrPath | None = ns.coverdir
self.tmp_dir: StrPath | None = ns.tempdir
@@ -377,8 +380,11 @@ class Regrtest:
return RunTests(
tests,
fail_fast=self.fail_fast,
+ fail_env_changed=self.fail_env_changed,
match_tests=self.match_tests,
ignore_tests=self.ignore_tests,
+ match_tests_dict=None,
+ rerun=None,
forever=self.forever,
pgo=self.pgo,
pgo_extended=self.pgo_extended,
@@ -393,6 +399,9 @@ class Regrtest:
gc_threshold=self.gc_threshold,
use_resources=self.use_resources,
python_cmd=self.python_cmd,
+ randomize=self.randomize,
+ random_seed=self.random_seed,
+ json_fd=None,
)
def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
diff --git a/Lib/test/libregrtest/runtests.py b/Lib/test/libregrtest/runtests.py
index 64f8f6a..656958f 100644
--- a/Lib/test/libregrtest/runtests.py
+++ b/Lib/test/libregrtest/runtests.py
@@ -16,29 +16,31 @@ class HuntRefleak:
@dataclasses.dataclass(slots=True, frozen=True)
class RunTests:
tests: TestTuple
- fail_fast: bool = False
- fail_env_changed: bool = False
- match_tests: FilterTuple | None = None
- ignore_tests: FilterTuple | None = None
- match_tests_dict: FilterDict | None = None
- rerun: bool = False
- forever: bool = False
- pgo: bool = False
- pgo_extended: bool = False
- output_on_failure: bool = False
- timeout: float | None = None
- verbose: int = 0
- quiet: bool = False
- hunt_refleak: HuntRefleak | None = None
- test_dir: StrPath | None = None
- use_junit: bool = False
- memory_limit: str | None = None
- gc_threshold: int | None = None
- use_resources: list[str] = dataclasses.field(default_factory=list)
- python_cmd: list[str] | None = None
+ fail_fast: bool
+ fail_env_changed: bool
+ match_tests: FilterTuple | None
+ ignore_tests: FilterTuple | None
+ match_tests_dict: FilterDict | None
+ rerun: bool
+ forever: bool
+ pgo: bool
+ pgo_extended: bool
+ output_on_failure: bool
+ timeout: float | None
+ verbose: int
+ quiet: bool
+ hunt_refleak: HuntRefleak | None
+ test_dir: StrPath | None
+ use_junit: bool
+ memory_limit: str | None
+ gc_threshold: int | None
+ use_resources: tuple[str]
+ python_cmd: tuple[str] | None
+ randomize: bool
+ random_seed: int | None
# On Unix, it's a file descriptor.
# On Windows, it's a handle.
- json_fd: int | None = None
+ json_fd: int | None
def copy(self, **override):
state = dataclasses.asdict(self)
diff --git a/Lib/test/libregrtest/setup.py b/Lib/test/libregrtest/setup.py
index 353a0f7..1c40b7c 100644
--- a/Lib/test/libregrtest/setup.py
+++ b/Lib/test/libregrtest/setup.py
@@ -1,5 +1,6 @@
import faulthandler
import os
+import random
import signal
import sys
import unittest
@@ -127,3 +128,6 @@ def setup_tests(runtests: RunTests):
if runtests.gc_threshold is not None:
gc.set_threshold(runtests.gc_threshold)
+
+ if runtests.randomize:
+ random.seed(runtests.random_seed)