Repository navigation
[ai misuse] fix(doctest): unwrap mock objects safely during collection - #15338
Closed
Rohan-Dedhia wants to merge 1 commit into
Closed
Rohan-Dedhia wants to merge 1 commit into
Rohan-Dedhia wants to merge 1 commit into
Conversation
Member
|
ai missuse/missatribution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15333.
Problem
When collecting doctests on modules that import
unittest.mock.call(or objects with dynamic attribute resolution that simulate mock wrapping),inspect.unwraptraverses__wrapped__attributes up tosys.getrecursionlimit(). Becausecall.__wrapped__generates a new_Callinstance on each access,inspect.unwrapbuilds amemodictionary containing thousands of distinct objects, allocating gigabytes of memory and potentially causing OOM when the recursion limit is raised.MockAwareDocTestFinderinsrc/_pytest/doctest.pypreviously overrode_findto run under_patch_unwrap_mock_aware()and skip_is_mockedobjects (#3456). That override was previously conditioned onsys.version_info < (3, 10)and was removed during cleanup of Python 3.9 support. However,inspect.unwrapin stdlib across Python 3.10+ still encounters unbounded recursion onunittest.mock.call.Solution
_findonMockAwareDocTestFinderto run underwith _patch_unwrap_mock_aware():and skip_is_mockedobjects.sys.setrecursionlimit(5000)).changelog/15333.bugfix.rst.