Issue 4677 - always relative path in skip report (#6953)

This commit is contained in:
Katarzyna Król 2020-04-17 07:28:36 +02:00 committed by GitHub
parent de6c28ed1f
commit 7789b51acb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 7 deletions

View File

@ -148,6 +148,7 @@ Justyna Janczyszyn
Kale Kundert
Karl O. Pinc
Katarzyna Jachim
Katarzyna Król
Katerina Koukiou
Kevin Cox
Kevin J. Foley

View File

@ -0,0 +1 @@
The path shown in the summary report for SKIPPED tests is now always relative. Previously it was sometimes absolute.

View File

@ -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():

View File

@ -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",
]
)

View File

@ -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