-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
Use module-level Random to shuffle tasks #840
Conversation
This allows test helpers etc. to reproduce scheduling-dependent heisenbugs by seeding the Random instance. Or at least ensures that *something else* will prevent reproductions instead.
Can you link to the issue thread where this was discussed, for context? (Not necessarily in the code, just here in the PR is fine.) Actual change LGTM |
Discussed here: HypothesisWorks/hypothesis#1709, and related to #239. I considered a few other ways to make the scheduler deterministic-on-demand:
|
Codecov Report
@@ Coverage Diff @@
## master #840 +/- ##
==========================================
- Coverage 99.23% 99.22% -0.01%
==========================================
Files 101 101
Lines 12182 12182
Branches 882 882
==========================================
- Hits 12089 12088 -1
- Misses 72 73 +1
Partials 21 21
Continue to review full report at Codecov.
|
I'm fine with the current PR, but noting here: The public API is an issue, but not a huge one: in the worst case, if we remove randomization, then the argument would just become a no-op, which would be totally backwards compatible. ("You asked for determinism, and you got determinism!") We could then deprecate it as lazily as we felt like. For the "enormous pain" part: are you imagining that Hypothesis will have hard-coded knowledge of Trio, and automatically patch the seed here whenever Hypothesis and Trio are both loaded in the same process? If so then I agree :-). But in the other design, where Hypothesis remains ignorant of Trio and we leave it to pytest-trio to hook them up, then a ...I guess the version where Hypothesis has hard-coded knowledge of Trio has compelling advantages though, if it's acceptable to the Hypothesis devs. Not everyone uses pytest-trio, and even if you use pytest-trio you might still have some tests where you call Another advantage of not exposing |
Our policy for Hypothesis is that the core engine cannot have any knowledge of other libraries; the interface layer can have generic hooks (e.g. I added one for pytest-trio which is now also used by pytest-asyncio), and the strategy layer can have whatever dependencies if it's under the So pytest-trio could easily inject a static This approach will also work without pytest-trio; you just need to do some (idempotent) setup by calling |
Oh, I was imagining that it would sample the seed from some strategy, not use a static one. But, anyway, I'm happy :-) Let's go ahead with this and we can always make it more complicated later if we need to. |
It does that for the stdlib, Numpy, and any registered random instances iff you use the Otherwise, we use a static seed to ensure it's still reproducible. In principle it would be nice to make using the random module without the corresponding strategy into a healthcheck error, but when we did that a few years ago it was a terrible user experience for not much gain. |
Huh, interesting! The more you know 🌠 |
This allows test helpers etc. to reproduce scheduling-dependent heisenbugs by seeding the
Random
instance. (or at least ensures that something else will prevent reproductions instead)I have draft patches against
pytest-trio
and Hypothesis to take advantage of this, but since this has no observable impact except to enable those future patches I thought this was a good place to start.