From cd580804a64a35d69dc789b05d7c3eeb777308f0 Mon Sep 17 00:00:00 2001 From: Harmin Parra Rueda Date: Tue, 25 Mar 2025 22:48:20 +0100 Subject: [PATCH 1/5] Fix for #11067 --- src/_pytest/skipping.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/skipping.py b/src/_pytest/skipping.py index 20efefb84df..2963960dcd7 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -278,7 +278,7 @@ def pytest_runtest_makereport( pass # don't interfere elif call.excinfo and isinstance(call.excinfo.value, xfail.Exception): assert call.excinfo.value.msg is not None - rep.wasxfail = "reason: " + call.excinfo.value.msg + rep.wasxfail = call.excinfo.value.msg rep.outcome = "skipped" elif not rep.skipped and xfailed: if call.excinfo: From 98f64fd5ac6e2f9323d381a7ad2cef588e9524c2 Mon Sep 17 00:00:00 2001 From: Harmin Parra Rueda Date: Sat, 29 Mar 2025 15:14:06 +0100 Subject: [PATCH 2/5] Update test_skipping.py --- testing/test_skipping.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 57113ba93d5..93b2b36469d 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -492,7 +492,7 @@ def test_this(): result = pytester.runpytest(p) result.stdout.fnmatch_lines(["*1 xfailed*"]) result = pytester.runpytest(p, "-rx") - result.stdout.fnmatch_lines(["*XFAIL*test_this*reason:*hello*"]) + result.stdout.fnmatch_lines(["*XFAIL*test_this*hello*"]) result = pytester.runpytest(p, "--runxfail") result.stdout.fnmatch_lines(["*1 pass*"]) From 2f8f3ff11335f93bec345aeaf3c318ee0a6c6b1d Mon Sep 17 00:00:00 2001 From: Harmin Parra Rueda Date: Sat, 29 Mar 2025 15:21:45 +0100 Subject: [PATCH 3/5] Update test_skipping.py --- testing/test_skipping.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 93b2b36469d..9a6c2c4b6aa 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -448,8 +448,8 @@ def test_this_false(): result = pytester.runpytest(p, "-rx") result.stdout.fnmatch_lines( [ - "*test_one*test_this - reason: *NOTRUN* noway", - "*test_one*test_this_true - reason: *NOTRUN* condition: True", + "*test_one*test_this - *NOTRUN* noway", + "*test_one*test_this_true - *NOTRUN* condition: True", "*1 passed*", ] ) @@ -510,7 +510,7 @@ def test_this(): result = pytester.runpytest(p) result.stdout.fnmatch_lines(["*1 xfailed*"]) result = pytester.runpytest(p, "-rx") - result.stdout.fnmatch_lines(["*XFAIL*test_this*reason:*hello*"]) + result.stdout.fnmatch_lines(["*XFAIL*test_this*hello*"]) result = pytester.runpytest(p, "--runxfail") result.stdout.fnmatch_lines( """ From 5946e9c926ae55df81df12a423b745efedb773f5 Mon Sep 17 00:00:00 2001 From: Harmin Parra Rueda Date: Sat, 29 Mar 2025 15:45:16 +0100 Subject: [PATCH 4/5] Create 11067.bugfix.rst --- changelog/11067.bugfix.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/11067.bugfix.rst diff --git a/changelog/11067.bugfix.rst b/changelog/11067.bugfix.rst new file mode 100644 index 00000000000..20da301323b --- /dev/null +++ b/changelog/11067.bugfix.rst @@ -0,0 +1,3 @@ +The test report ``wasxfail`` attribute value is not consistent for XFailed tests. It yields a slightly different value when the xfailure occurs due to the use of the ``@pytest.mark.xfail`` marker, and when it occurs due to an explicit call to the ``pytest.fail`` function. + +This bugfix ensures a coherent value for the ``wasxfail`` attribute for XFailed tests. From 6e62c139987d8ae06c51f3cdef61b1bf68243495 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 2 Apr 2025 07:38:57 -0300 Subject: [PATCH 5/5] Update 11067.bugfix.rst --- changelog/11067.bugfix.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog/11067.bugfix.rst b/changelog/11067.bugfix.rst index 20da301323b..4e3cb8e7dd7 100644 --- a/changelog/11067.bugfix.rst +++ b/changelog/11067.bugfix.rst @@ -1,3 +1,3 @@ -The test report ``wasxfail`` attribute value is not consistent for XFailed tests. It yields a slightly different value when the xfailure occurs due to the use of the ``@pytest.mark.xfail`` marker, and when it occurs due to an explicit call to the ``pytest.fail`` function. +The test report is now consistent regardless if the test xfailed via :ref:`pytest.mark.xfail ` or :func:`pytest.fail`. -This bugfix ensures a coherent value for the ``wasxfail`` attribute for XFailed tests. +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.