Fold skipped tests with global pytestmark variable

This commit is contained in:
prokaktus 2017-08-12 16:50:54 +03:00
parent 9e62a31b63
commit 98bf5fc9be
4 changed files with 38 additions and 3 deletions

View File

@ -117,6 +117,7 @@ Matt Bachmann
Matt Duck
Matt Williams
Matthias Hafner
Maxim Filipenko
mbyt
Michael Aquilina
Michael Birtwell

View File

@ -345,6 +345,12 @@ def folded_skips(skipped):
for event in skipped:
key = event.longrepr
assert len(key) == 3, (event, key)
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
# TODO: revisit after marks scope would be fixed
if event.when == 'setup' and 'skip' in keywords and 'pytestmark' not in keywords:
key = (key[0], None, key[2], )
d.setdefault(key, []).append(event)
l = []
for key, events in d.items():
@ -367,6 +373,11 @@ def show_skipped(terminalreporter, lines):
for num, fspath, lineno, reason in fskips:
if reason.startswith("Skipped: "):
reason = reason[9:]
lines.append(
"SKIP [%d] %s:%d: %s" %
(num, fspath, lineno + 1, reason))
if lineno is not None:
lines.append(
"SKIP [%d] %s:%d: %s" %
(num, fspath, lineno + 1, reason))
else:
lines.append(
"SKIP [%d] %s: %s" %
(num, fspath, reason))

1
changelog/2549.feature Normal file
View File

@ -0,0 +1 @@
Report only once tests with global ``pytestmark`` variable.

View File

@ -676,6 +676,7 @@ def test_skip_reasons_folding():
ev1.longrepr = longrepr
ev2 = X()
ev2.when = "execute"
ev2.longrepr = longrepr
ev2.skipped = True
@ -713,6 +714,27 @@ def test_skipped_reasons_functional(testdir):
assert result.ret == 0
def test_skipped_folding(testdir):
testdir.makepyfile(
test_one="""
import pytest
pytestmark = pytest.mark.skip("Folding")
def setup_function(func):
pass
def test_func():
pass
class TestClass(object):
def test_method(self):
pass
""",
)
result = testdir.runpytest('-rs')
result.stdout.fnmatch_lines([
"*SKIP*2*test_one.py: Folding"
])
assert result.ret == 0
def test_reportchars(testdir):
testdir.makepyfile("""
import pytest