Skip to content

Commit 75c3e5d

Browse files
committed
Better xfail mechanism
1 parent 0643e35 commit 75c3e5d

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

tests/coveragetest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ def setUp(self):
101101
self.last_command_output = None
102102
self.last_module_name = None
103103

104-
def xfail(self, msg):
105-
"""Mark this test as an expected failure."""
106-
pytest.xfail(msg)
107-
108104
def clean_local_file_imports(self):
109105
"""Clean up the results of calls to `import_local_file`.
110106
@@ -501,3 +497,8 @@ def command_line(args):
501497
script = CoverageScript()
502498
ret = script.command_line(shlex.split(args))
503499
return ret
500+
501+
502+
def xfail(condition, reason):
503+
"""A decorator to mark as test as expected to fail."""
504+
return pytest.mark.xfail(condition, reason=reason, strict=True)

tests/test_arcs.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"""Tests for coverage.py's arc measurement."""
55

6-
from tests.coveragetest import CoverageTest
6+
from tests.coveragetest import CoverageTest, xfail
77

88
import coverage
99
from coverage import env
@@ -629,9 +629,8 @@ def test_finally_in_loop(self):
629629
)
630630

631631

632+
@xfail(env.PYBEHAVIOR.bpo39114, reason="https://bugs.python.org/issue39114")
632633
def test_break_through_finally(self):
633-
if env.PYBEHAVIOR.bpo39114:
634-
self.xfail("https://bugs.python.org/issue39114")
635634
if env.PYBEHAVIOR.finally_jumps_back:
636635
arcz = ".1 12 23 34 3D 45 56 67 68 7A 7D 8A A3 A7 BC CD D."
637636
else:
@@ -655,9 +654,8 @@ def test_break_through_finally(self):
655654
arcz_missing="3D BC CD",
656655
)
657656

657+
@xfail(env.PYBEHAVIOR.bpo39114, "https://bugs.python.org/issue39114")
658658
def test_continue_through_finally(self):
659-
if env.PYBEHAVIOR.bpo39114:
660-
self.xfail("https://bugs.python.org/issue39114")
661659
if env.PYBEHAVIOR.finally_jumps_back:
662660
arcz = ".1 12 23 34 3D 45 56 67 68 73 7A 8A A3 A7 BC CD D."
663661
else:
@@ -694,9 +692,8 @@ def test_finally_in_loop_bug_92(self):
694692
arcz=".1 12 23 35 56 61 17 7.",
695693
)
696694

695+
@xfail(env.PYBEHAVIOR.bpo39114, "https://bugs.python.org/issue39114")
697696
def test_bug_212(self):
698-
if env.PYBEHAVIOR.bpo39114:
699-
self.xfail("https://bugs.python.org/issue39114")
700697
# "except Exception as e" is crucial here.
701698
# Bug 212 said that the "if exc" line was incorrectly marked as only
702699
# partially covered.
@@ -818,9 +815,8 @@ def test_multiple_except_clauses(self):
818815
arcz_unpredicted="45 7A AB",
819816
)
820817

818+
@xfail(env.PYBEHAVIOR.bpo39114, "https://bugs.python.org/issue39114")
821819
def test_return_finally(self):
822-
if env.PYBEHAVIOR.bpo39114:
823-
self.xfail("https://bugs.python.org/issue39114")
824820
if env.PYBEHAVIOR.finally_jumps_back:
825821
arcz = ".1 12 29 9A AB BC C-1 -23 34 45 5-2 57 75 38 8-2"
826822
else:
@@ -842,9 +838,8 @@ def check_token(data):
842838
arcz=arcz,
843839
)
844840

841+
@xfail(env.PYBEHAVIOR.bpo39114, "https://bugs.python.org/issue39114")
845842
def test_except_jump_finally(self):
846-
if env.PYBEHAVIOR.bpo39114:
847-
self.xfail("https://bugs.python.org/issue39114")
848843
if env.PYBEHAVIOR.finally_jumps_back:
849844
arcz = (
850845
".1 1Q QR RS ST TU U. "
@@ -898,9 +893,8 @@ def func(x):
898893
arcz_unpredicted="67",
899894
)
900895

896+
@xfail(env.PYBEHAVIOR.bpo39114, "https://bugs.python.org/issue39114")
901897
def test_else_jump_finally(self):
902-
if env.PYBEHAVIOR.bpo39114:
903-
self.xfail("https://bugs.python.org/issue39114")
904898
if env.PYBEHAVIOR.finally_jumps_back:
905899
arcz = (
906900
".1 1S ST TU UV VW W. "
@@ -1522,9 +1516,8 @@ async def print_sum(x, y): # 8
15221516
)
15231517
self.assertEqual(self.stdout(), "Compute 1 + 2 ...\n1 + 2 = 3\n")
15241518

1519+
@xfail(env.PYVERSION == (3, 9, 0, 'alpha', 2, 0), "https://bugs.python.org/issue39166")
15251520
def test_async_for(self):
1526-
if env.PYVERSION == (3, 9, 0, 'alpha', 2, 0):
1527-
self.xfail("https://bugs.python.org/issue39166")
15281521
self.check_coverage("""\
15291522
import asyncio
15301523

tests/test_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from coverage.misc import NotPython
1010
from coverage.parser import PythonParser
1111

12-
from tests.coveragetest import CoverageTest
12+
from tests.coveragetest import CoverageTest, xfail
1313
from tests.helpers import arcz_to_arcs
1414

1515

@@ -137,9 +137,12 @@ def test_token_error(self):
137137
'''
138138
""")
139139

140+
141+
@xfail(
142+
env.PYPY3 and env.PYPYVERSION >= (7, 3, 0),
143+
"https://bitbucket.org/pypy/pypy/issues/3139",
144+
)
140145
def test_decorator_pragmas(self):
141-
if env.PYPY3 and env.PYPYVERSION >= (7, 3, 0): # pragma: obscure
142-
self.xfail("https://bitbucket.org/pypy/pypy/issues/3139")
143146
parser = self.parse_source("""\
144147
# 1
145148

tests/test_process.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from coverage.files import python_reported_file
2424
from coverage.misc import output_encoding
2525

26-
from tests.coveragetest import CoverageTest, TESTS_DIR
26+
from tests.coveragetest import CoverageTest, TESTS_DIR, xfail
2727
from tests.helpers import re_lines
2828

2929

@@ -742,12 +742,14 @@ def test_fullcoverage(self): # pragma: no metacov
742742
# about 5.
743743
self.assertGreater(line_counts(data)['os.py'], 50)
744744

745+
@xfail(
746+
env.PYPY3 and env.PYPYVERSION >= (7, 1, 1),
747+
"https://bitbucket.org/pypy/pypy/issues/3074"
748+
)
745749
def test_lang_c(self):
746750
if env.JYTHON:
747751
# Jython as of 2.7.1rc3 won't compile a filename that isn't utf8.
748752
self.skipTest("Jython can't handle this test")
749-
if env.PYPY3 and env.PYPYVERSION >= (7, 1, 1): # pragma: obscure
750-
self.xfail("https://bitbucket.org/pypy/pypy/issues/3074")
751753
# LANG=C forces getfilesystemencoding on Linux to 'ascii', which causes
752754
# failures with non-ascii file names. We don't want to make a real file
753755
# with strange characters, though, because that gets the test runners

0 commit comments

Comments
 (0)