From 7789b51acb3cb98f2bdd59fb0cd926376d65f1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katarzyna=20Kr=C3=B3l?= <38542683+CarycaKatarzyna@users.noreply.github.com> Date: Fri, 17 Apr 2020 07:28:36 +0200 Subject: [PATCH] Issue 4677 - always relative path in skip report (#6953) --- AUTHORS | 1 + changelog/4677.bugfix.rst | 1 + src/_pytest/terminal.py | 14 +++++++++----- testing/test_skipping.py | 2 +- testing/test_terminal.py | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 changelog/4677.bugfix.rst 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