-
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
Unable to use random in pytest.mark.parametrize with xdist and randomly #75
Comments
Ah, I see, this is because you're randomizing things at import time, outside of pytest's cycle. I'm not sure your suggestion will work in all cases, because it's probably possible for tests to be imported before the configure step even occurs 🤔 Your use case also seems a bit weird. If you want random data, why not randomize it during the test? And if you want parametrized tests, why not fix the parameters? |
It probably won't cover all cases, yes, but I've never seen a case where some tests are imported from other files that are not gathered directly by pytest. Randomizing data during the test doesn't show parameters in pytest output, and I don't want to put excessive logging into each test case that uses random data. Also, I think that input data shouldn't be a test's concern where it's possible. |
The point of pytest-randomly is so that you can rerun with the same seed and discover the failing case. You don't need to log up front the randomly selected values, if a test fails just rerun with the same seed and e.g. Also by randomizing your test cases in this way you're preventing some pytest features from working such as I seriously recommend just doing: def test_foo():
a = random.random()
b = random.random()
c = random.random() That said I will consider adding the reseed on |
Could you please clarify on |
They don't use |
Oh, I'm blind, sorry. |
Closing, as I said I don't think pytest-randomly should be catering for this kind of randomness. |
there is a real value for running random values. I'v just ran with this issue myself. |
@OfirAharon can your tests not be altered to randomize within the tests, rather than at import time, as above? Please open a new issue if not, and explain with code samples. This issue is nearly 2 years old. |
Packages:
Example code:
Example result:
From what I could gather, it's possible to fix it simply by adding
to
pytest_randomly.py
. But I've never written a single plugin for pytest and I've read only some excerpts from the documentation, so I may be wrong.The text was updated successfully, but these errors were encountered: