diff --git a/AUTHORS b/AUTHORS index 84833c642..cc4aaa6ad 100644 --- a/AUTHORS +++ b/AUTHORS @@ -117,6 +117,7 @@ Matt Bachmann Matt Duck Matt Williams Matthias Hafner +Maxim Filipenko mbyt Michael Aquilina Michael Birtwell diff --git a/_pytest/skipping.py b/_pytest/skipping.py index 5f927a6b4..2b5d0dded 100644 --- a/_pytest/skipping.py +++ b/_pytest/skipping.py @@ -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)) diff --git a/changelog/2549.feature b/changelog/2549.feature new file mode 100644 index 000000000..4866d990d --- /dev/null +++ b/changelog/2549.feature @@ -0,0 +1 @@ +Report only once tests with global ``pytestmark`` variable. \ No newline at end of file diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 6608ccadf..1fbb9ed0f 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -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