Merge pull request #2680 from prokaktus/skipping-same-module

Fold skipped tests with global pytestmark variable
This commit is contained in:
Ronny Pfannschmidt 2017-08-15 10:52:24 +02:00 committed by GitHub
commit 5c0feb2877
4 changed files with 38 additions and 3 deletions

View File

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

View File

@ -345,6 +345,12 @@ def folded_skips(skipped):
for event in skipped: for event in skipped:
key = event.longrepr key = event.longrepr
assert len(key) == 3, (event, key) 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) d.setdefault(key, []).append(event)
l = [] l = []
for key, events in d.items(): for key, events in d.items():
@ -367,6 +373,11 @@ def show_skipped(terminalreporter, lines):
for num, fspath, lineno, reason in fskips: for num, fspath, lineno, reason in fskips:
if reason.startswith("Skipped: "): if reason.startswith("Skipped: "):
reason = reason[9:] reason = reason[9:]
if lineno is not None:
lines.append( lines.append(
"SKIP [%d] %s:%d: %s" % "SKIP [%d] %s:%d: %s" %
(num, fspath, lineno + 1, reason)) (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 ev1.longrepr = longrepr
ev2 = X() ev2 = X()
ev2.when = "execute"
ev2.longrepr = longrepr ev2.longrepr = longrepr
ev2.skipped = True ev2.skipped = True
@ -713,6 +714,27 @@ def test_skipped_reasons_functional(testdir):
assert result.ret == 0 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): def test_reportchars(testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import pytest import pytest