Fix for nested Mocketizer's decorators - #327
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #327 +/- ##
==========================================
+ Coverage 98.09% 98.85% +0.76%
==========================================
Files 22 22
Lines 1207 1224 +17
==========================================
+ Hits 1184 1210 +26
+ Misses 23 14 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
The new regression test performs an unguarded real HTTP request (likely flaky/offline-dependent) and should be consistent with existing SKIP_TRUE_HTTP-guarded true-HTTP tests.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes a regression where nested Mocketizer/@mocketize activations could fail to restore the original socket patches and/or STRICT mode, causing STRICT mode to leak into subsequent tests (Issue #326).
Changes:
- Add nested enable/disable depth tracking in
mocket.injectto avoid overwriting original patch-restore values during re-entrant activation. - Make
MocketizerrestoreMocketMode.STRICT/STRICT_ALLOWEDon exit even when teardown/disable raises. - Add regression tests for STRICT mode and patch restoration; bump pre-commit hook revisions.
File summaries
| File | Description |
|---|---|
| tests/test_mode.py | Adds a regression test ensuring STRICT mode from an inner @mocketize does not leak beyond an outer context. |
| tests/test_mocket.py | Adds a regression test for nested Mocketizer ensuring socket patches and STRICT mode are restored. |
| mocket/inject.py | Introduces _enable_depth to make patching/restoring re-entrant-safe for nested activations. |
| mocket/decorators/mocketizer.py | Stores/restores prior STRICT mode settings on exit (with finally for robustness). |
| .pre-commit-config.yaml | Updates ruff and rstcheck hook versions. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: mindflayer <527325+mindflayer@users.noreply.github.com>
Co-authored-by: mindflayer <527325+mindflayer@users.noreply.github.com>
…mocket into fix-nested-decorators
|



Fix for #326