You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently was thinking about what to do to make the use of random numbers more reproducible. Currently, when a test using a random number fails, there is no way of backtracking what random number seed was actually used so that the test can be reproduced.
So...
While using tox I noticed it always sets PYTHONHASHSEED itself (to a random value, but printing that value) to ensure people can reproduce tests failing due to anything that has to do with that environment variable
That way pytest could always prepare random to be in the identical state for each tests and remember the seed value and print it, hinting at the fact that there are random numbers at play here.
I haven't given too much thought about how to achieve this behaviour (monkeypatching the random module I guess) but first wanted to hear what you guys think.
Originally reported by: Nils Werner (BitBucket: nils-werner, GitHub: nils-werner)
I recently was thinking about what to do to make the use of random numbers more reproducible. Currently, when a test using a random number fails, there is no way of backtracking what random number seed was actually used so that the test can be reproduced.
So...
tox
I noticed it always setsPYTHONHASHSEED
itself (to a random value, but printing that value) to ensure people can reproduce tests failing due to anything that has to do with that environment variablepytest-django
I noticed they always set the database back into its initial state and require the tests to be marked (or have adb
fixture) to touch the dabase.This brought me to the idea of controlling the
random
module a bit more to:For example, currently you can do
Which gives absolutely no information why and in what situations the (rather idiotic) test is failing.
Or, when you have two tests
The order of execution changes the values each test sees (particularily troubling with
xdist
I guess)ideally, the above code should fail and should be replaced with
That way pytest could always prepare
random
to be in the identical state for each tests and remember the seed value and print it, hinting at the fact that there are random numbers at play here.I haven't given too much thought about how to achieve this behaviour (monkeypatching the
random
module I guess) but first wanted to hear what you guys think.The text was updated successfully, but these errors were encountered: