Skip to content

Incorrect paths to tests in output when using multiple test locations and --rootdir/pytest.ini #13254

Open
@ugomancz

Description

@ugomancz

Description

When running pytest with paths to tests in multiple directories while setting rootdir (or having a pytest.ini file) to one of the test directories, paths to tests from other directories in the output are wrong.

Consider the following file structure:

pytest_rootdir_issue
└─tests
  ├─a
  │ └─aa
  │    └─test_a.py
  │
  └─b
    └─bb
       └─test_b.py

When running pytest inside tests/a/ and giving it paths to both tests (./aa ../b/bb) while having a pytest.ini in tests/a/aa (or setting --rootdir to ./aa), path to the test_b.py in the output is invalid. The only valid path to the test_b.py is after the <- arrow sign, but that can cause quite confusing and invalid-looking output, especially with multiple test locations, long paths, and many tests.

Output with the incorrect path:

================================= test session starts =================================
platform win32 -- Python 3.12.7, pytest-8.3.4, pluggy-1.5.0 -- C:\pytest_issue\.venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\pytest_issue\tests\a\aa
collected 2 items

aa\test_a.py::test_a PASSED                                                      [ 50%]
aa\test_b.py::test_b <- ..\..\b\bb\test_b.py PASSED                              [100%]

================================== 2 passed in 0.01s ==================================

The aa\test_b.py::test_b test path is invalid.

pip list

Package   Version
--------- -------
colorama  0.4.6
iniconfig 2.0.0
packaging 24.2
pip       24.2
pluggy    1.5.0
pytest    8.3.4

pytest and operating system versions

pytest 8.3.4, Windows 11 Business 24H2 (build 26100.3194)

Minimal example

Minimal example is prepared in this repository: https://github.com/ugomancz/pytest_rootdir_issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: collectionrelated to the collection phasetype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions