diff --git a/changelog/7076.bugfix.rst b/changelog/7076.bugfix.rst new file mode 100644 index 000000000..5d9749c69 --- /dev/null +++ b/changelog/7076.bugfix.rst @@ -0,0 +1 @@ +The path of file skipped by ``@pytest.mark.skip`` in the SKIPPED report is now relative to invocation directory. Previously it was relative to root directory. diff --git a/src/_pytest/skipping.py b/src/_pytest/skipping.py index fe8742c66..62a9ca491 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -168,8 +168,8 @@ def pytest_runtest_makereport(item, call): # to point to the item definition, otherwise it will display # the location of where the skip exception was raised within pytest _, _, reason = rep.longrepr - filename, line = item.location[:2] - rep.longrepr = filename, line + 1, reason + filename, line = item.reportinfo()[:2] + rep.longrepr = str(filename), line + 1, reason # called by terminalreporter progress reporting diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 8b1cdd527..32634d784 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -1176,3 +1176,20 @@ def test_importorskip(): match="^could not import 'doesnotexist': No module named .*", ): pytest.importorskip("doesnotexist") + + +def test_relpath_rootdir(testdir): + testdir.makepyfile( + **{ + "tests/test_1.py": """ + import pytest + @pytest.mark.skip() + def test_pass(): + pass + """, + } + ) + result = testdir.runpytest("-rs", "tests/test_1.py", "--rootdir=tests") + result.stdout.fnmatch_lines( + ["SKIPPED [[]1[]] tests/test_1.py:2: unconditional skip"] + )