MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_xfail_handling

Function test_xfail_handling

testing/test_stepwise.py:201–250  ·  view source on GitHub ↗

Ensure normal xfail is ignored, and strict xfail interrupts the session in sw mode (#5547)

(pytester: Pytester, monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

199
200
201def test_xfail_handling(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
202 """Ensure normal xfail is ignored, and strict xfail interrupts the session in sw mode
203
204 (#5547)
205 """
206 monkeypatch.setattr("sys.dont_write_bytecode", True)
207
208 contents = """
209 import pytest
210 def test_a(): pass
211
212 @pytest.mark.xfail(strict={strict})
213 def test_b(): assert {assert_value}
214
215 def test_c(): pass
216 def test_d(): pass
217 """
218 pytester.makepyfile(contents.format(assert_value="0", strict="False"))
219 result = pytester.runpytest("--sw", "-v")
220 result.stdout.fnmatch_lines(
221 [
222 "*::test_a PASSED *",
223 "*::test_b XFAIL *",
224 "*::test_c PASSED *",
225 "*::test_d PASSED *",
226 "* 3 passed, 1 xfailed in *",
227 ]
228 )
229
230 pytester.makepyfile(contents.format(assert_value="1", strict="True"))
231 result = pytester.runpytest("--sw", "-v")
232 result.stdout.fnmatch_lines(
233 [
234 "*::test_a PASSED *",
235 "*::test_b FAILED *",
236 "* Interrupted*",
237 "* 1 failed, 1 passed in *",
238 ]
239 )
240
241 pytester.makepyfile(contents.format(assert_value="0", strict="True"))
242 result = pytester.runpytest("--sw", "-v")
243 result.stdout.fnmatch_lines(
244 [
245 "*::test_b XFAIL *",
246 "*::test_c PASSED *",
247 "*::test_d PASSED *",
248 "* 2 passed, 1 deselected, 1 xfailed in *",
249 ]
250 )
251
252
253def test_stepwise_skip_is_independent(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 5

setattrMethod · 0.80
fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
formatMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected