pytest-dev / pytest-dev/pytest
Race condition when doing non toplevel pytest plugin check
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Pytest will sometimes throw a non toplevel pytest plugin error ("Failed: Defining 'pytest_plugins' in a non-top-level conftest is no longer supported") and sometimes not, without any changes to my conftest.py or project structure. More specifically, if I move an addopts argument specified in an .ini file onto the command line, i'm able to make this error go away (requires --cache-clear to reproduce consistently).
I've traced this down to the line where the error is being thrown, and what I've found is that one case PytestPluginManager will have self._configured set to True at the time of the check whereas it's False when the argument is moved.
Does someone more familiar with the code know how/when self._configured is set, and whether it is possible for a race condition to occur? e.g. maybe the code that is supposed to set the field sometimes completes before the check happens and sometimes doesn't? I unfortunately don't have a minimal repro case but am hoping that whether this is possible is obvious to someone who knows how this code works.
pytest version is 6.1.1
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 at src/_pytest/config/init.py around line 616, where the non-top-level pytest_plugins error is raised. Compare runs with addopts in the .ini file versus on the command line, using --cache-clear as reported, and inspect when PytestPluginManager._configured changes. Done means determining whether the inconsistent check is a race or another ordering issue and identifying the required regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100