Skip to content

Improve error for mistaken self fixture - #14908

Open
meetpandya4715 wants to merge 1 commit into
pytest-dev:mainfrom
meetpandya4715:fix-self-fixture-hint
Open

Improve error for mistaken self fixture#14908
meetpandya4715 wants to merge 1 commit into
pytest-dev:mainfrom
meetpandya4715:fix-self-fixture-hint

Conversation

@meetpandya4715

Copy link
Copy Markdown

Summary

  • add a targeted hint when a bare test function mistakenly declares self and pytest reports it as a missing fixture
  • add a regression test for the rendered error
  • add a changelog entry

This addresses the maintainer-approved first case in #12907. It deliberately leaves the more complex missing-self method case unchanged.

Why

The existing fixture 'self' not found message assumes the reader already understands pytest fixtures. For beginners who accidentally write a standalone test like def test_something(self), a short hint points directly to the likely mistake without changing fixture discovery or execution.

The hint is emitted only for the normal missing-fixture path when the unresolved name is exactly self; recursive fixture dependency errors are unaffected.

Validation

  • focused fixture lookup tests: 2 passed
  • complete testing/python/fixtures.py module: 241 passed, 3 xfailed
  • repository changed-files pre-commit suite: passed, including Ruff, formatting, codespell, and mypy

AI assistance

Codex assisted with issue research and implementation. I reviewed and understand the complete change and will own the contribution and follow-up discussion.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 19, 2026
@meetpandya4715
meetpandya4715 marked this pull request as ready for review August 19, 2026 13:53
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.

1 participant