pytest-dev / pytest-dev/pytest

[FR] when fixture is not found, but avaliable in siebling conftests, give them as hints

Open
#10,151 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: fixtures type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

What's the problem this feature will solve?

when moving some fixtures from a pytest plugin to a conftest,
i missed a very specific use in a sibling file

# excerpt of directory structure
mypkg:
  fixtures: fixture was here
  tests:
     conftest.py: fixture is here now
     test_foo.py: uses fixture
  utils:
    tests:
      test_bar: uses fixture

as i was seeing the errors for the missing fixture,
i kept reading the last parts of the filenames (tests/... in good old PEBKAC fashion
completely missing the fact hat the prefix was indeed different (mypkg/tests vs mypkg/utils/tests)

the error simply told me fixture 'myfixyture' not found + a list of available fixtures, which albeit correct, just fueled my misguided Monday morning focus

Describe the solution you'd like

in addition to the error telling the name i would like to see the additional details displayed

fixture 'myfixture' not found
hint: definitions of 'myfixture' found in 'mypkg/tests/conftest.py' 
>       available fixtures for `mypkg/utils/tests/test_bar.py': ...  

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the missing-fixture case using the shown conftest.py and sibling test layout, then trace pytest's fixture-not-found error reporting. Start with the code that builds the available-fixtures message. Done means the error identifies matching fixture definitions in sibling conftest.py files without losing the existing available-fixtures output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.