Make pytest functions reproducible (1/2)#1036
Conversation
c2cf2bc to
141c154
Compare
|
@jonbrenas This is ready now, follow up to #1008 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1036 +/- ##
==========================================
+ Coverage 90.25% 90.26% +0.01%
==========================================
Files 51 51
Lines 5631 5659 +28
==========================================
+ Hits 5082 5108 +26
- Misses 549 551 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks @jwgarber. Why do the new |
8922101 to
2262070
Compare
|
Unfortunately the |
|
@jonbrenas Any other comments on this? |
This converts about half of the pytest functions so their random number generation is reproducible. The name of the pytest function is used to seed the RNG to ensure all functions generate independent random numbers.
This needs to be in a top-level conftest.py, otherwise it won't always get printed on startup.
This converts about half of the pytest functions so their random number generation is reproducible. The name of the pytest function test case is used to seed the RNG to ensure all functions generate independent random numbers. There are a few instances where the Numpy RNG has slightly different behaviour than the Python ones (e.g.
random.randint()includes the endpoint by default whilerng.integers()does not), so that had to be adapted. There are also a few cases where the numpy types have to be cast to Python types to make the type checker happy (e.g.np.int64 -> int), otherwise it's quite similar.This was tested by trying to reproduce this flaky test failure. After about 140 trials I was able to find a random seed that caused the crash (325228949307297790525745584766237006555 in this case), and I am able to reliably reproduce this crash with that seed. Once this is finished the next job will be debugging that.
There are a lot of functions to convert, so the other half will be done in another PR since this one is large already.
While testing this I noticed that the global seed wasn't being printed in the workflow logs, even though it is when you run tests individually. Apparently this is because the seed needs to be printed from the top-level
conftest.py, otherwise it won't get picked up when runningpytest -v tests. Anyway, I rearranged some of the files so it works now.