-
Notifications
You must be signed in to change notification settings - Fork 30
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
feature: add the option --randomly-seed-per-test
to use a different seed for each test
#617
base: main
Are you sure you want to change the base?
Conversation
f61a6ea
to
cdd56f0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this.
I think we can make it the default behaviour, no option. Otherwise it’s just another thing other users have to learn about and consider activating.
f4c777a
to
946b247
Compare
… seed for each test
946b247
to
8b80740
Compare
It's done but there is an inconsistency with how seeding works with faker. I'm not sure what would be least surprising for someone given the docs from faker. pytest-randomly/tests/test_pytest_randomly.py Lines 674 to 692 in 8b80740
https://faker.readthedocs.io/en/master/pytest-fixtures.html#seeding-configuration |
hi folks, any chance this gets merged and released soon? thank you for the help! |
Sounds like you should change your test to either work with the same seed of data or change the data generator to not generate invalid data? I don't believe the changes proposed here would even help with your situation either way. |
This would be very useful indeed. In the meantime I worked around this in my own project using @pytest.fixture(autouse=True)
# autouse fixtures with leading underscores are ignored. See https://github.com/pytest-dev/pytest/issues/12404.
def emulate_pytest_randomly_pull_request_617(request: pytest.FixtureRequest) -> None: # noqa: PT004
# pytest-randomly sets `randomly_seed` to an integer at pytest_configure time. See
# https://github.com/pytest-dev/pytest-randomly/blob/8a3a241/src/pytest_randomly/__init__.py#L138.
#
# We include that integer to preserve the behavior of an explicit `--randomly-seed <int>` flag
# passed on the command line while also giving each test a unique seed.
request.config.option.randomly_seed += int(hashlib.sha512(request.node.nodeid.encode()).hexdigest(), base=16) |
Resolves #600
I'm tempted to make it the default behavior but this is safer.