You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Upon further investigation, I think I have identified the issue.
During the collection of the tests, when nodeid is being calculated, if the path to the test is outside of the config.rootpath, then paths to the tests' locations given as CLI argument are used for nodeid calculation.
This happens here
However, later, when the terminal output is being created (here), nodeid is joined with config.rootpath, resulting in the invalid path seen in the output.
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:
When running pytest inside
tests/a/
and giving it paths to both tests (./aa ../b/bb
) while having a pytest.ini intests/a/aa
(or setting--rootdir
to./aa
), path to thetest_b.py
in the output is invalid. The only valid path to thetest_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:
The
aa\test_b.py::test_b
test path is invalid.pip list
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
The text was updated successfully, but these errors were encountered: