Repository navigation
doctest: prevent deep unwrap recursion on mock.call with elevated recursion limit - #15419
Abdur-Rafay-AR wants to merge 1 commit into
Conversation
…ursion limit (pytest-dev#15333) Signed-off-by: Abdur-Rafay-AR <abdurrafay.tech@gmail.com>
|
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it. Closing. This fails basic validation: the regression test passes on main without the fix (0.77 s, ~600 MB at limit 10 000), so it tests nothing. The code is the "possible fix" from #15333 and nearly identical to #15338, which was already closed as AI misuse. Its The fix is #15420: it hooks The comment and PR body restate the issue without disclosing AI use. See our AI policy: https://github.com/pytest-dev/pytest/blob/main/CONTRIBUTING.rst Generated by Claude Code |
Fixes #15333
Cause
In commit
bb712f151("Remove support for Python 3.9"), theMockAwareDocTestFinder._findoverride was removed under the assumption that it was only needed for Python < 3.10. However, on all Python versions (3.10+), stdlibDocTestFinder._is_routineunwraps module attributes withinspect.unwrap(obj)and only catchesValueError. When a module importsunittest.mock.call,mock.call.__wrapped__returns a new_Callwith an extended name. This triggers an unbounded unwrapping chain up tosys.getrecursionlimit(), consuming gigabytes of memory and leading to OOM or execution stalls.Solution
Restore the
_findoverride inMockAwareDocTestFinderinsrc/_pytest/doctest.pywithout the version guard:_patch_unwrap_mock_aware()so that_is_mocked(obj)terminates unwrapping at depth 1.test_doctest_mock_call_elevated_recursion_limitintesting/test_doctest.pyverifying that doctest collection on a module importingcallwithsys.setrecursionlimit(10_000)finishes immediately.changelog/15333.bugfix.rst.