pytest-dev / pytest-dev/pytest
pytest silently chooses the wrong fixture when two plugins declare a fixture with the same name
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
The magic name-matching of pytest's fixtures can lead to namespace clashes, apart from being unpythonic (see #3834). Getting a wrong fixture may lead to hard-to-debug errors, especially if one does not know the plugin code and therefore does not know if one plugin may legitimately call the other plugin's code. Thus, I believe that pytest should not allow a fixture to be used whose name clashes between two declarations (Python Zen: In the face of ambiguity, refuse the temptation to guess.). Instead, it should raise an explicit error, including a hint to the test-writer how they may resolve the ambiguity.
The environment where this bug was observed was the following:
python 3.6.1
This is pytest version 3.5.0
pytest-sanic-0.1.13
pytest-benchmark-3.1.1
pytest-aiohttp-0.3.0
where both aiohttp and sanic provide a test_client fixture.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the fixture collision with pytest-sanic, pytest-benchmark, and pytest-aiohttp, focusing on the competing test_client fixtures described in the issue. Trace how pytest selects fixtures and define the explicit error and resolution hint; done means ambiguous declarations no longer silently select one fixture.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100