-
Notifications
You must be signed in to change notification settings - Fork 586
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_module() not working, or am I misunderstanding the documentation?
#1813
Comments
Quick Fix - UPDATEI just found a cleaner version of the "quick fix": @given(randoms())
def test_random_module_quick_fix(hypothesis_random):
with patch('random.randint', hypothesis_random.randint):
a = random.randint(0, 100)
b = random.randint(0, 100)
print(f'QF: a={a} b={b} | Expected seed: {hypothesis_random.seed} ')But it still doesn't answer the question of whether or not it is normal for the |
|
I don't think you're missing anything! This looks like it's almost certainly a bug in Hypothesis. Just trying to figure out what's going on now. My guess is we broke this with some recent changes to how we handle random state and apparently don't have an adequate test to cover that we actually ever produce different random answers here. 😞 |
|
Huh. Longer standing issue than I thought it was - this was actually introduced in May last year. Good spot! |
|
Oh wow! Now that was efficient! Thanks for the fix @DRMacIver |
Hi,
I would like to test a non-deterministic piece of code in a way that'd allow me to reproduce a failure. I thought the
random_module()strategy would help me do that, but it doesn't seem to work as I expected.Example
I would think that the following example would return different values of
aandbfor each iteration of the tests. From what I understood, therandom_module()strategy is supposed to callrandom.seed(SEED)before the test (whereSEEDis actuallyrand_mod.seedin this example).But the result looks like this:
Quick Fix
A quick fix seems to be to generate
integers()and then use that as a seed. I tested it seems it fits the reproducibility criteria. But obviously if I could use therandom_module()strategy it'd be much more flexible and readable.Questions
random_module()strategy actually do?I couldn't see any difference when using it vs not.
Thanks for the great work on the framework, besides the headache of this afternoon trying to figure out the
random_module()thing, I found the rest of the framework incredibly simple to use. After a few minutes only I was able to significantly shrink down some particularly verbose tests. Great job, that's amazing 😍The text was updated successfully, but these errors were encountered: