fix: fix multiple bugs in _apply_deterministic_patches#1823
fix: fix multiple bugs in _apply_deterministic_patches#1823aseembits93 wants to merge 2 commits intomainfrom
Conversation
- Add re-entrancy guard to prevent infinite recursion if pytest_configure runs twice - Remove all unnecessary calls to original functions in mocks (overhead + failure point) - Actually patch datetime.datetime.now/utcnow via DeterministicDatetime subclass - Fix datetime.now(tz=None) returning tz-aware instead of naive datetime - Patch missing time functions: time_ns, monotonic, monotonic_ns - Remove useless np.random.default_rng(42) that created and discarded a Generator - Remove redundant try/except around os.urandom (os is always available) - Update tests to cover all new patches and datetime behavior Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @aseembits93's task in 3m 40s —— View job PR Review Summary
Prek Checks✅ Mypy NotesTwo new mypy errors introduced by this PR in
Auto-fixed (committed): removed unused Code ReviewThe fixes in this PR are correct and well-motivated. A few observations:
Duplicate DetectionNo duplicates detected. The Test CoverageAll 23 tests pass. Coverage for Last updated: 2026-03-12 |
Co-authored-by: Aseem Saxena <undefined@users.noreply.github.com>
⚡️ Codeflash found optimizations for this PR📄 13% (0.13x) speedup for
|
Summary
_DETERMINISTIC_PATCHES_APPLIEDflag to prevent infinite recursion ifpytest_configureruns twiceuuid.uuid1()can raise on some platforms)datetime.datetime.now/utcnow: Previous code stored mocks tobuiltinsbut never patcheddatetime.datetime. Now uses aDeterministicDatetimesubclass. Also fixesnow(tz=None)incorrectly returning tz-aware datetimetime_ns,monotonic,monotonic_ns(perf_counter_nsintentionally not patched — used by profiling infrastructure)np.random.default_rng(42): Created a Generator and discarded it — no effectos.urandom:osis always availableTest plan
uv run pytest tests/test_pytest_plugin_deterministic_patches.py -v— 23 tests passuv run pytest tests/ -x --timeout=60— 2645 passed, 0 faileduv run prek run --from-ref origin/main— ruff check + format pass🤖 Generated with Claude Code