Skip to content

Commit 682013d

Browse files
Make wasxfail consistent (#13328)
Previously, xfailed tests via the marker would have a special `"reason: "` string prefixed to it. Removed the prefix so the `wasxfail` attribute is now consistent regardless the method used. Fix #11067 --------- Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 0c45497 commit 682013d

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

changelog/11067.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The test report is now consistent regardless if the test xfailed via :ref:`pytest.mark.xfail <pytest.mark.xfail ref>` or :func:`pytest.fail`.
2+
3+
Previously, *xfailed* tests via the marker would have the string ``"reason: "`` prefixed to the message, while those *xfailed* via the function did not. The prefix has been removed.

src/_pytest/skipping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def pytest_runtest_makereport(
278278
pass # don't interfere
279279
elif call.excinfo and isinstance(call.excinfo.value, xfail.Exception):
280280
assert call.excinfo.value.msg is not None
281-
rep.wasxfail = "reason: " + call.excinfo.value.msg
281+
rep.wasxfail = call.excinfo.value.msg
282282
rep.outcome = "skipped"
283283
elif not rep.skipped and xfailed:
284284
if call.excinfo:

testing/test_skipping.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ def test_this_false():
448448
result = pytester.runpytest(p, "-rx")
449449
result.stdout.fnmatch_lines(
450450
[
451-
"*test_one*test_this - reason: *NOTRUN* noway",
452-
"*test_one*test_this_true - reason: *NOTRUN* condition: True",
451+
"*test_one*test_this - *NOTRUN* noway",
452+
"*test_one*test_this_true - *NOTRUN* condition: True",
453453
"*1 passed*",
454454
]
455455
)
@@ -492,7 +492,7 @@ def test_this():
492492
result = pytester.runpytest(p)
493493
result.stdout.fnmatch_lines(["*1 xfailed*"])
494494
result = pytester.runpytest(p, "-rx")
495-
result.stdout.fnmatch_lines(["*XFAIL*test_this*reason:*hello*"])
495+
result.stdout.fnmatch_lines(["*XFAIL*test_this*hello*"])
496496
result = pytester.runpytest(p, "--runxfail")
497497
result.stdout.fnmatch_lines(["*1 pass*"])
498498

@@ -510,7 +510,7 @@ def test_this():
510510
result = pytester.runpytest(p)
511511
result.stdout.fnmatch_lines(["*1 xfailed*"])
512512
result = pytester.runpytest(p, "-rx")
513-
result.stdout.fnmatch_lines(["*XFAIL*test_this*reason:*hello*"])
513+
result.stdout.fnmatch_lines(["*XFAIL*test_this*hello*"])
514514
result = pytester.runpytest(p, "--runxfail")
515515
result.stdout.fnmatch_lines(
516516
"""

0 commit comments

Comments
 (0)