Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random_seeder option to define entry points to use #497

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/pytest_randomly/__init__.py
Expand Up @@ -99,6 +99,13 @@ def pytest_addoption(parser: Parser) -> None:
default=True,
help="Stop pytest-randomly from randomly reorganizing the test order.",
)
group._addoption(
"--randomly-seeder",
action="append",
dest="randomly_seeders",
help="""Give the name of a pytest_randomly.random_seeder entry point to use.
Multiple entry points can be set by defining this option multiple times""",
)


def pytest_configure(config: Config) -> None:
Expand Down Expand Up @@ -166,8 +173,10 @@ def _reseed(config: Config, offset: int = 0) -> int:
np_random.set_state(np_random_states[numpy_seed])

if entrypoint_reseeds is None:
seeders: list[str] = config.getoption("randomly_seeders")
eps = entry_points(group="pytest_randomly.random_seeder")
entrypoint_reseeds = [e.load() for e in eps]
seeders = [] if seeders is None else seeders
entrypoint_reseeds = [e.load() for e in eps if e.name in seeders]
for reseed in entrypoint_reseeds:
reseed(seed)

Expand Down