Skip to content

Skip mock objects with _mock_name=None in wrapped fixture lookup - #15315

Open
rinopatrick wants to merge 4 commits into
pytest-dev:mainfrom
rinopatrick:fix/15281-mock-unwrap-hang
Open

rinopatrick wants to merge 4 commits into
pytest-dev:mainfrom
rinopatrick:fix/15281-mock-unwrap-hang

Conversation

@rinopatrick

Copy link
Copy Markdown

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:

  • New regression test (fails before, passes after).
  • Changelog entry added.
  • Added myself to AUTHORS.

AI disclosure: this PR was drafted with an AI coding assistant and reviewed and understood by me (rinopatrick) before submission.

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
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9.2.0: collection of a module importing unittest.mock.call uses GBs of memory when recursionlimit is raised (regression from 9.1.1)

1 participant