Fix pytest-randomly seed overflow in numpy legacy API#732
Open
I-am-Uchenna wants to merge 2 commits into
Open
Conversation
Wraps numpy.random.seed to handle seeds exceeding 2**32 - 1, which older pytest-randomly versions can generate. Fixes PyPortfolio#725.
7 tests covering boundary cases, None seeds, and determinism preservation for the numpy.random.seed wrapper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #725
Problem
When
pytest-randomly(older versions) generates seeds that exceed2**32 - 1,numpy.random.seed()raises aValueErrorbecause its legacy API only accepts seeds in the range[0, 2**32 - 1].This surfaces as random, hard-to-reproduce test failures depending on the seed pytest-randomly picks.
Fix
Adds a
tests/conftest.pythat monkey-patchesnumpy.random.seedat module load time to constrain any integer seed viaseed % (2**32). Non-integer andNoneseeds pass through unchanged.The patch is minimal and project-scoped - it only affects the test suite, not library code.
Tests
Adds
tests/test_conftest.pywith 7 tests covering:All tests pass. Both files are Black-formatted.
Reproduction