diff --git a/AUTHORS b/AUTHORS index bbb8e463d..cfbcf432b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -148,6 +148,7 @@ Justyna Janczyszyn Kale Kundert Karl O. Pinc Katarzyna Jachim +Katarzyna Król Katerina Koukiou Kevin Cox Kevin J. Foley diff --git a/changelog/4677.bugfix.rst b/changelog/4677.bugfix.rst new file mode 100644 index 000000000..6b7d2cf17 --- /dev/null +++ b/changelog/4677.bugfix.rst @@ -0,0 +1 @@ +The path shown in the summary report for SKIPPED tests is now always relative. Previously it was sometimes absolute. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index a99463fe8..52c04a49c 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -1027,7 +1027,7 @@ class TerminalReporter: def show_skipped(lines: List[str]) -> None: skipped = self.stats.get("skipped", []) - fskips = _folded_skips(skipped) if skipped else [] + fskips = _folded_skips(self.startdir, skipped) if skipped else [] if not fskips: return verbose_word = skipped[0]._get_verbose_word(self.config) @@ -1153,11 +1153,13 @@ def _get_line_with_reprcrash_message(config, rep, termwidth): return line -def _folded_skips(skipped): +def _folded_skips(startdir, skipped): d = {} for event in skipped: - key = event.longrepr - assert len(key) == 3, (event, key) + assert len(event.longrepr) == 3, (event, event.longrepr) + fspath, lineno, reason = event.longrepr + # For consistency, report all fspaths in relative form. + fspath = startdir.bestrelpath(py.path.local(fspath)) keywords = getattr(event, "keywords", {}) # folding reports with global pytestmark variable # this is workaround, because for now we cannot identify the scope of a skip marker @@ -1167,7 +1169,9 @@ def _folded_skips(skipped): and "skip" in keywords and "pytestmark" not in keywords ): - key = (key[0], None, key[2]) + key = (fspath, None, reason) + else: + key = (fspath, lineno, reason) d.setdefault(key, []).append(event) values = [] for key, events in d.items(): diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 67714d030..8b1cdd527 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -758,7 +758,7 @@ def test_skipped_reasons_functional(testdir): result = testdir.runpytest("-rs") result.stdout.fnmatch_lines_random( [ - "SKIPPED [[]2[]] */conftest.py:4: test", + "SKIPPED [[]2[]] conftest.py:4: test", "SKIPPED [[]1[]] test_one.py:14: via_decorator", ] ) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 88d564519..d2857ca77 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -2001,7 +2001,7 @@ def test_skip_reasons_folding(): ev3.longrepr = longrepr ev3.skipped = True - values = _folded_skips([ev1, ev2, ev3]) + values = _folded_skips(py.path.local(), [ev1, ev2, ev3]) assert len(values) == 1 num, fspath, lineno, reason = values[0] assert num == 3