Skip to content

Conversation

@RonnyPfannschmidt
Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt force-pushed the ronny/fix-13564-warn-on-decorated-fixturedef branch from c879256 to 9e7e132 Compare September 24, 2025 07:12
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Sep 24, 2025
@RonnyPfannschmidt RonnyPfannschmidt force-pushed the ronny/fix-13564-warn-on-decorated-fixturedef branch from 9e7e132 to ac8d323 Compare September 24, 2025 07:14
@RonnyPfannschmidt RonnyPfannschmidt force-pushed the ronny/fix-13564-warn-on-decorated-fixturedef branch from b79b0ed to 59a31ca Compare September 24, 2025 07:16
RonnyPfannschmidt and others added 2 commits October 18, 2025 12:02
Refactor the wrapped fixture detection logic to safely handle:
- Mock objects (which have _mock_name attribute)
- Proxy objects with problematic __class__ properties
- Wrapper loops (like in mock.call)
- Objects that raise exceptions during isinstance checks

The new _find_wrapped_fixture_def() method walks the wrapper chain
more safely and avoids infinite loops and errors from special objects.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Prevent OOM crash when encountering objects with self-referential
__wrapped__ attributes. The loop detection logic now checks object
IDs at the start of each iteration and includes a maximum depth
limit as an additional safeguard.

The original code had a timing issue where it checked id(wrapped)
against seen after fetching __wrapped__ but before updating current,
which failed to detect self-referential objects properly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a warning mechanism to detect when pytest fixtures are wrapped with custom decorators, which prevents pytest from discovering them during collection. The warning helps developers understand why their fixtures might not be working as expected.

Key Changes:

  • Added a warning system that detects fixtures wrapped in decorators using functools.wraps
  • Implemented safe wrapper chain traversal with loop detection and special object handling
  • Added comprehensive test coverage for the new warning functionality

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/_pytest/fixtures.py Implements the core detection logic for wrapped fixtures and issues warnings when found
testing/python/fixtures.py Adds test case to verify the warning is correctly issued for decorated fixtures
changelog/13564.improvement.rst Documents the new warning feature for wrapped fixtures

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

"""
from _pytest.compat import safe_getattr

# Skip mock objects (they have _mock_name attribute)
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment should clarify why mock objects need to be skipped. Consider: 'Skip mock objects (they have _mock_name attribute) to avoid false positives when traversing their wrapper chains.'

Suggested change
# Skip mock objects (they have _mock_name attribute)
# Skip mock objects (they have _mock_name attribute) to avoid false positives when traversing their wrapper chains.

Copilot uses AI. Check for mistakes.
return None

# Try to get the next wrapped object using safe_getattr to handle
# "evil objects" that raise on attribute access (see issue #214)
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The reference to 'issue #214' is unclear without context. Consider specifying the full issue reference (e.g., 'pytest issue #214') or linking to the relevant documentation.

Suggested change
# "evil objects" that raise on attribute access (see issue #214)
# "evil objects" that raise on attribute access (see pytest issue #214: https://github.com/pytest-dev/pytest/issues/214)

Copilot uses AI. Check for mistakes.
Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment on lines +1809 to +1813
wrapped = safe_getattr(current, "__wrapped__", None)
if wrapped is None:
break

current = wrapped
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wrapped = safe_getattr(current, "__wrapped__", None)
if wrapped is None:
break
current = wrapped
current = safe_getattr(current, "__wrapped__", None)

redundant with start-of-loop logic

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.

Fixture definition check in parsefactories is too strict

2 participants