-
Notifications
You must be signed in to change notification settings - Fork 22
patch randomness while running tests #378
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
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
(`patch-randomness`) Here is the optimized version of your program, rewritten for much faster runtime, based on optimizing the parts most costly in your profiling (import overhead, fixed object creation, unnecessary calls to originals in mocks, and making sure patching is only done once). **Major optimizations:** - **Moved imports and all constant/time-invariant objects outside the function** (`fixed_datetime`, etc), preventing repeated slow computations on repeated executions. - **Patched only once:** Added a sentinel attribute (`_is_patched`) on the `time` module to avoid re-patching on repeated calls, reducing imports and setup. - **Skipped all "call original" for mocks:** There’s no need to call the original functions just for "performance characteristics". - **Used function attributes instead of closure state for `mock_perf_counter`** (faster and leaner). - **Avoided repeatedly creating the default_rng object in NumPy**, instead storing it on `np` for re-use. - **No functional change**: All mocks now instantly return deterministic values. **Net effect:** The patch takes almost no time for subsequent calls, saves massive time on repeated calls, and is much lighter on memory, especially for fixed objects. All original test reproducibility and function signatures are preserved.
⚡️ Codeflash found optimizations for this PR📄 8,957% (89.57x) speedup for
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
User description
we can't find optimizations where the function to optimize calls any of the non-deterministic functions below.
PR Type
Enhancement, Tests
Description
Apply deterministic randomness patches
Override time, perf_counter, uuid random
Patch os.urandom and seed numpy
Add comprehensive deterministic patch tests
Changes walkthrough 📝
pytest_plugin.py
Implement deterministic randomness patchescodeflash/verification/pytest_plugin.py
test_pytest_plugin_deterministic_patches.py
Add deterministic patch teststests/test_pytest_plugin_deterministic_patches.py