Skip to content

Commit 802c77a

Browse files
authored
[4.6] Handle xfail(strict=True) properly in --step-wise mode (#… (#5556)
[4.6] Handle xfail(strict=True) properly in --step-wise mode (#5555)
2 parents 46a0888 + acb62ba commit 802c77a

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

changelog/5547.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``--step-wise`` now handles ``xfail(strict=True)`` markers properly.

src/_pytest/stepwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def pytest_collection_modifyitems(self, session, config, items):
7373

7474
def pytest_runtest_logreport(self, report):
7575
# Skip this hook if plugin is not active or the test is xfailed.
76-
if not self.active or "xfail" in report.keywords:
76+
if not self.active:
7777
return
7878

7979
if report.failed:

testing/test_stepwise.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- coding: utf-8 -*-
2+
import sys
3+
24
import pytest
35

46

@@ -166,3 +168,57 @@ def test_stop_on_collection_errors(broken_testdir, broken_first):
166168
files.reverse()
167169
result = broken_testdir.runpytest("-v", "--strict-markers", "--stepwise", *files)
168170
result.stdout.fnmatch_lines("*errors during collection*")
171+
172+
173+
def test_xfail_handling(testdir):
174+
"""Ensure normal xfail is ignored, and strict xfail interrupts the session in sw mode
175+
176+
(#5547)
177+
"""
178+
contents = """
179+
import pytest
180+
def test_a(): pass
181+
182+
@pytest.mark.xfail(strict={strict})
183+
def test_b(): assert {assert_value}
184+
185+
def test_c(): pass
186+
def test_d(): pass
187+
"""
188+
testdir.makepyfile(contents.format(assert_value="0", strict="False"))
189+
result = testdir.runpytest("--sw", "-v")
190+
result.stdout.fnmatch_lines(
191+
[
192+
"*::test_a PASSED *",
193+
"*::test_b XFAIL *",
194+
"*::test_c PASSED *",
195+
"*::test_d PASSED *",
196+
"* 3 passed, 1 xfailed in *",
197+
]
198+
)
199+
200+
testdir.makepyfile(contents.format(assert_value="1", strict="True"))
201+
result = testdir.runpytest("--sw", "-v")
202+
result.stdout.fnmatch_lines(
203+
[
204+
"*::test_a PASSED *",
205+
"*::test_b FAILED *",
206+
"* Interrupted*",
207+
"* 1 failed, 1 passed in *",
208+
]
209+
)
210+
211+
# because we are writing to the same file, mtime might not be affected enough to
212+
# invalidate the cache, making this next run flaky
213+
if not sys.dont_write_bytecode:
214+
testdir.tmpdir.join("__pycache__").remove()
215+
testdir.makepyfile(contents.format(assert_value="0", strict="True"))
216+
result = testdir.runpytest("--sw", "-v")
217+
result.stdout.fnmatch_lines(
218+
[
219+
"*::test_b XFAIL *",
220+
"*::test_c PASSED *",
221+
"*::test_d PASSED *",
222+
"* 2 passed, 1 deselected, 1 xfailed in *",
223+
]
224+
)

0 commit comments

Comments
 (0)