Repository navigation
Skip mock objects with _mock_name=None in wrapped fixture lookup - #15315
Open
rinopatrick wants to merge 4 commits into
Open
rinopatrick wants to merge 4 commits into
rinopatrick wants to merge 4 commits into
Conversation
unittest.mock.call is a _Call whose _mock_name is None and whose __wrapped__ returns a new object on every access, so inspect.unwrap only stopped at the recursion limit (slow collection + huge memory with a raised limit). Treat any object with a _mock_name attribute as a mock. Fixes pytest-dev#15281
This branch has not been deployed
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.
Closes #15281.
unittest.mock.call is a _Call whose _mock_name is None and whose wrapped returns a new object on every access, so inspect.unwrap in _find_wrapped_fixture_def only stopped at the recursion limit. Collection took 38s / 5.4GB with a raised limit. Any object with a _mock_name attribute is now treated as a mock and skipped before unwrapping.
The reproducer from the issue now collects in under a second.
Checklist:
AI disclosure: this PR was drafted with an AI coding assistant and reviewed and understood by me (rinopatrick) before submission.