Skip to content

Commit 832c89d

Browse files
committed
Test for pytest.mark.xfail with non-Python Item
1 parent 1a88a91 commit 832c89d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

testing/test_skipping.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,3 +969,26 @@ def test_func():
969969
result.stdout.fnmatch_lines(
970970
"*Using pytest.skip outside of a test is not allowed*"
971971
)
972+
973+
974+
def test_mark_xfail_item(testdir):
975+
# Ensure pytest.mark.xfail works with non-Python Item
976+
testdir.makeconftest("""
977+
import pytest
978+
979+
class MyItem(pytest.Item):
980+
nodeid = 'foo'
981+
def setup(self):
982+
marker = pytest.mark.xfail(True, reason="Expected failure")
983+
self.add_marker(marker)
984+
def runtest(self):
985+
assert False
986+
987+
def pytest_collect_file(path, parent):
988+
return MyItem("foo", parent)
989+
""")
990+
result = testdir.inline_run()
991+
passed, skipped, failed = result.listoutcomes()
992+
assert not failed
993+
xfailed = [r for r in skipped if hasattr(r, 'wasxfail')]
994+
assert xfailed

0 commit comments

Comments
 (0)