pytest-dev / pytest-dev/pytest

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

Open
#13,254 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: collection type: bug
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked minimal example with tests in both directories and a pytest.ini or --rootdir setting, then compare the reported node paths with the actual test paths. Trace the output path formatting and consider the issue fixed when every displayed test path is valid and unambiguous for multiple test locations.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.