Skip to content

Conftest file is loaded multiple times #13296

Open
@wassupxP

Description

@wassupxP

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:

pytest_bug.zip

Steps to reproduce:

  1. unzip pytest_bug.zip
  2. python -m pytest .\pytest_bug\Reproducer\
    (note that running python -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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform: windowswindows platform-specific problemtopic: configrelated to config handling, argument parsing and config file

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions