Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

* Fix a crash with Faker installed when explicitly enabling and disabling the plugin (via ``-p randomly -p no:randomly``).

Thanks to mojosan77 for the report in `Issue #718 <https://github.com/pytest-dev/pytest-randomly/issues/718>`__.

* Drop Python 3.9 support.

4.0.1 (2025-09-12)
Expand Down
17 changes: 12 additions & 5 deletions src/pytest_randomly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,15 @@ def _crc32(string: str) -> int:
if have_faker: # pragma: no branch

@fixture(autouse=True)
def faker_seed(pytestconfig: Config, request: SubRequest) -> int:
result: int = pytestconfig.getoption("randomly_seed") + _crc32(
request.node.nodeid
)
return result
def faker_seed(pytestconfig: Config, request: SubRequest) -> Any:
from faker.contrib.pytest.plugin import DEFAULT_SEED

seed = pytestconfig.getoption("randomly_seed")
if seed in ("default", "last"):
# pytest-randomly has been imported but disabled, so
# pytest_configure hasn't run to set the seed. Fall back to
# Faker's default seed.
return DEFAULT_SEED
else:
result: int = seed + _crc32(request.node.nodeid)
return result
12 changes: 12 additions & 0 deletions tests/test_pytest_randomly.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,18 @@ def test_two(faker):
out.assert_outcomes(passed=2)


def test_faker_enabled_disabled(monkeypatch, ourtester):
ourtester.makepyfile(
test_one="""
def test_one(faker):
assert faker.name() == 'Norma Fisher'
"""
)

out = ourtester.runpytest("-p", "randomly", "-p", "no:randomly")
out.assert_outcomes(passed=1)


def test_model_bakery(ourtester):
"""
Check the Model Bakery random generator is reset between tests.
Expand Down