From 402ee6fb9da7eb5e5d702b7794fb0ff6573816fc Mon Sep 17 00:00:00 2001 From: Katarzyna Date: Sun, 3 May 2020 22:56:38 +0200 Subject: [PATCH 1/4] Relative path to invocationdir instead rootdir. --- changelog/7076.trivial.rst | 1 + src/_pytest/skipping.py | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog/7076.trivial.rst diff --git a/changelog/7076.trivial.rst b/changelog/7076.trivial.rst new file mode 100644 index 000000000..5d9749c69 --- /dev/null +++ b/changelog/7076.trivial.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..22e51bc4b 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -169,6 +169,7 @@ def pytest_runtest_makereport(item, call): # the location of where the skip exception was raised within pytest _, _, reason = rep.longrepr filename, line = item.location[:2] + filename = item.config.rootdir.join(filename) rep.longrepr = filename, line + 1, reason From a5bcd0655f7baa00f82d9a74bc2e62dbf63e8b4a Mon Sep 17 00:00:00 2001 From: Katarzyna Date: Mon, 4 May 2020 00:04:38 +0200 Subject: [PATCH 2/4] Test relapth when rootdir != invocationdir. --- testing/test_skipping.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 8b1cdd527..e7edf139d 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -1176,3 +1176,23 @@ 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 + """, + "tests/sub_tests/test_empty.py": """ + pass + """, + } + ) + result = testdir.runpytest("-rs", "tests/test_1.py", "--rootdir=tests/sub_tests") + result.stdout.fnmatch_lines( + ["SKIPPED [[]1[]] tests/test_1.py:2: unconditional skip"] + ) From 9b423710aa79e5c388e7ccfd9f67946cf317307f Mon Sep 17 00:00:00 2001 From: Katarzyna Date: Mon, 4 May 2020 00:34:19 +0200 Subject: [PATCH 3/4] Remove unnecessary file in test. --- testing/test_skipping.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/testing/test_skipping.py b/testing/test_skipping.py index e7edf139d..32634d784 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -1187,12 +1187,9 @@ def test_relpath_rootdir(testdir): def test_pass(): pass """, - "tests/sub_tests/test_empty.py": """ - pass - """, } ) - result = testdir.runpytest("-rs", "tests/test_1.py", "--rootdir=tests/sub_tests") + result = testdir.runpytest("-rs", "tests/test_1.py", "--rootdir=tests") result.stdout.fnmatch_lines( ["SKIPPED [[]1[]] tests/test_1.py:2: unconditional skip"] ) From 16a44823eb053ded01136c7110760c8639c7343b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 4 May 2020 19:09:29 -0300 Subject: [PATCH 4/4] Use reportinfo() instead of location in skipping message --- changelog/{7076.trivial.rst => 7076.bugfix.rst} | 0 src/_pytest/skipping.py | 5 ++--- 2 files changed, 2 insertions(+), 3 deletions(-) rename changelog/{7076.trivial.rst => 7076.bugfix.rst} (100%) diff --git a/changelog/7076.trivial.rst b/changelog/7076.bugfix.rst similarity index 100% rename from changelog/7076.trivial.rst rename to changelog/7076.bugfix.rst diff --git a/src/_pytest/skipping.py b/src/_pytest/skipping.py index 22e51bc4b..62a9ca491 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -168,9 +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] - filename = item.config.rootdir.join(filename) - rep.longrepr = filename, line + 1, reason + filename, line = item.reportinfo()[:2] + rep.longrepr = str(filename), line + 1, reason # called by terminalreporter progress reporting