Skip to content

Commit 5c0feb2

Browse files
Merge pull request #2680 from prokaktus/skipping-same-module
Fold skipped tests with global pytestmark variable
2 parents 5f17caa + 98bf5fc commit 5c0feb2

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Matt Bachmann
117117
Matt Duck
118118
Matt Williams
119119
Matthias Hafner
120+
Maxim Filipenko
120121
mbyt
121122
Michael Aquilina
122123
Michael Birtwell

_pytest/skipping.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ def folded_skips(skipped):
345345
for event in skipped:
346346
key = event.longrepr
347347
assert len(key) == 3, (event, key)
348+
keywords = getattr(event, 'keywords', {})
349+
# folding reports with global pytestmark variable
350+
# this is workaround, because for now we cannot identify the scope of a skip marker
351+
# TODO: revisit after marks scope would be fixed
352+
if event.when == 'setup' and 'skip' in keywords and 'pytestmark' not in keywords:
353+
key = (key[0], None, key[2], )
348354
d.setdefault(key, []).append(event)
349355
l = []
350356
for key, events in d.items():
@@ -367,6 +373,11 @@ def show_skipped(terminalreporter, lines):
367373
for num, fspath, lineno, reason in fskips:
368374
if reason.startswith("Skipped: "):
369375
reason = reason[9:]
370-
lines.append(
371-
"SKIP [%d] %s:%d: %s" %
372-
(num, fspath, lineno + 1, reason))
376+
if lineno is not None:
377+
lines.append(
378+
"SKIP [%d] %s:%d: %s" %
379+
(num, fspath, lineno + 1, reason))
380+
else:
381+
lines.append(
382+
"SKIP [%d] %s: %s" %
383+
(num, fspath, reason))

changelog/2549.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Report only once tests with global ``pytestmark`` variable.

testing/test_skipping.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ class X(object):
676676
ev1.longrepr = longrepr
677677

678678
ev2 = X()
679+
ev2.when = "execute"
679680
ev2.longrepr = longrepr
680681
ev2.skipped = True
681682

@@ -713,6 +714,27 @@ def doskip():
713714
assert result.ret == 0
714715

715716

717+
def test_skipped_folding(testdir):
718+
testdir.makepyfile(
719+
test_one="""
720+
import pytest
721+
pytestmark = pytest.mark.skip("Folding")
722+
def setup_function(func):
723+
pass
724+
def test_func():
725+
pass
726+
class TestClass(object):
727+
def test_method(self):
728+
pass
729+
""",
730+
)
731+
result = testdir.runpytest('-rs')
732+
result.stdout.fnmatch_lines([
733+
"*SKIP*2*test_one.py: Folding"
734+
])
735+
assert result.ret == 0
736+
737+
716738
def test_reportchars(testdir):
717739
testdir.makepyfile("""
718740
import pytest

0 commit comments

Comments
 (0)