From 034b7dc0a11bc264fa181f404132bf098d2c5676 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 10 Sep 2025 00:36:34 +0100 Subject: [PATCH] Generate default seed on demand --- src/pytest_randomly/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pytest_randomly/__init__.py b/src/pytest_randomly/__init__.py index b893fb7..63f10f8 100644 --- a/src/pytest_randomly/__init__.py +++ b/src/pytest_randomly/__init__.py @@ -57,7 +57,8 @@ have_numpy = False -default_seed = random.Random().getrandbits(32) +def make_seed() -> int: + return random.Random().getrandbits(32) def seed_type(string: str) -> str | int: @@ -112,13 +113,13 @@ def pytest_configure(config: Config) -> None: "The cacheprovider plugin is required to use 'last'" ) assert config.cache is not None - seed = config.cache.get("randomly_seed", default_seed) + seed = config.cache.get("randomly_seed", make_seed()) elif seed_value == "default": if hasattr(config, "workerinput"): # pragma: no cover # pytest-xdist: use seed generated on main. seed = config.workerinput["randomly_seed"] else: - seed = default_seed + seed = make_seed() else: seed = seed_value if hasattr(config, "cache"):