Skip to content

Commit

Permalink
Merge pull request pytest-dev#2680 from prokaktus/skipping-same-module
Browse files Browse the repository at this point in the history
Fold skipped tests with global pytestmark variable
  • Loading branch information
RonnyPfannschmidt authored Aug 15, 2017
2 parents 5f17caa + 98bf5fc commit 5c0feb2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Matt Bachmann
Matt Duck
Matt Williams
Matthias Hafner
Maxim Filipenko
mbyt
Michael Aquilina
Michael Birtwell
Expand Down
17 changes: 14 additions & 3 deletions _pytest/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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 change: 1 addition & 0 deletions changelog/2549.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Report only once tests with global ``pytestmark`` variable.
22 changes: 22 additions & 0 deletions testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ class X(object):
ev1.longrepr = longrepr

ev2 = X()
ev2.when = "execute"
ev2.longrepr = longrepr
ev2.skipped = True

Expand Down Expand Up @@ -713,6 +714,27 @@ def doskip():
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
Expand Down

0 comments on commit 5c0feb2

Please sign in to comment.