You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--doctest-modules uses GBs of memory on modules importing unittest.mock.call when the recursion limit is raised #15333
On Python 3.10+, the stdlib DocTestFinder._is_routine calls inspect.unwrap(obj) on every module attribute and only catches ValueError. mock.call.__wrapped__ keeps returning a new _Call with a longer name, so unwrapping runs until sys.getrecursionlimit(). Memory grows roughly quadratically with the limit.
pytest used to guard against this. MockAwareDocTestFinder._find skipped _is_mocked objects and ran the stdlib _find under _patch_unwrap_mock_aware() (#3456, python/cpython#69718). That override was limited to Python < 3.10 and was removed along with 3.9 support in bb712f1. _patch_unwrap_mock_aware itself is now only used by its own test.
Possible fix
Restore the _find override for all Python versions (about 14 lines in src/_pytest/doctest.py). I prototyped it locally: the reproducer drops to 0.09 s / 33 MB and the full test suite passes. A regression test is still needed.
Activity