pytest-dev / pytest-dev/pytest
Conftest file is loaded multiple times
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
Dear Pytest team,
I’ve encountered a bug on Windows where conftest.py is loaded multiple times if the path to the test files is specified with differing case on a case-insensitive file system. This behavior triggers the following error (on minimal reproduction example) - ValueError: option names {'--dummy-option'} already added
Minimal reproduction example:
Steps to reproduce:
unzip pytest_bug.zippython -m pytest .\pytest_bug\Reproducer\
(note that runningpython -m pytest .\pytest_bug\reproducer\will finish with 0 collected tests as expected)
Pip list output and OS version
OS version: Windows 11
Python Version: 3.12.9
(.venv) PS C:\venvs\reproducer\pytest_bug> python -m pip list
Package Version
--------- -------
colorama 0.4.6
iniconfig 2.0.0
packaging 24.2
pip 24.3.1
pluggy 1.5.0
pytest 8.3.5
Potentional fix
Resolving the path fixes the issue, but I am not sure whether it might not have impact on something else.
$ git diff
diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py
index 56b047196..39f61daaf 100644
--- a/src/_pytest/config/__init__.py
+++ b/src/_pytest/config/__init__.py
@@ -643,7 +643,7 @@ class PytestPluginManager(PluginManager):
if self._noconftest:
return
- directory = self._get_directory(path)
+ directory = self._get_directory(path.resolve())
Thank you.
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 in src/_pytest/config/init.py at PytestPluginManager and the directory lookup in conftest loading. Reproduce on Windows with the provided archive and the differing-case pytest paths, then verify that conftest.py is loaded once, the duplicate option error is gone, and expected test collection still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100