Skip to content

Commit 92ea931

Browse files
authored
Improve reporting in case of xfail (#194)
The test status report of subtests that xfail now retains the subtest description and fixes the summary line to take xfail and xpass into account.
1 parent 9737d2b commit 92ea931

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ UNRELEASED
77
*UNRELEASED*
88

99
* Print output "dots" for successful unittest subtests (`#164`_).
10+
* Improved reporting in case subtests raise `pytest.xfail` (`#194`_).
1011

1112
.. _#164: https://github.com/pytest-dev/pytest-subtests/issues/164
13+
.. _#194: https://github.com/pytest-dev/pytest-subtests/pull/194
1214

1315
0.14.1
1416
------

src/pytest_subtests/plugin.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,26 @@ def pytest_report_teststatus(
457457
if report.when != "call" or not isinstance(report, SubTestReport):
458458
return None
459459

460-
if hasattr(report, "wasxfail"):
461-
return None
462-
463460
outcome = report.outcome
464461
description = report.sub_test_description()
465-
if report.passed:
462+
463+
if hasattr(report, "wasxfail"):
464+
if outcome == "skipped":
465+
category = "xfailed"
466+
short = "y" # x letter is used for regular xfail, y for subtest xfail
467+
status = "SUBXFAIL"
468+
elif outcome == "passed":
469+
category = "xpassed"
470+
short = "Y" # X letter is used for regular xpass, Y for subtest xpass
471+
status = "SUBXPASS"
472+
else:
473+
# This should not normally happen, unless some plugin is setting wasxfail without
474+
# the correct outcome. Pytest expects the call outcome to be either skipped or passed in case of xfail.
475+
# Let's pass this report to the next hook.
476+
return None
477+
short = "" if config.option.no_subtests_shortletter else short
478+
return f"subtests {category}", short, f"{description} {status}"
479+
elif report.passed:
466480
short = "" if config.option.no_subtests_shortletter else ","
467481
return f"subtests {outcome}", short, f"{description} SUBPASS"
468482
elif report.skipped:

tests/test_subtests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_foo(subtests):
131131
pytest.importorskip("xdist")
132132
result = pytester.runpytest("-n1")
133133
expected_lines = ["1 worker [1 item]"]
134-
expected_lines += ["* 1 passed, 3 xfailed, 2 subtests passed in *"]
134+
expected_lines += ["* 1 passed, 2 subtests passed, 3 subtests xfailed in *"]
135135
result.stdout.fnmatch_lines(expected_lines)
136136

137137
def test_typing_exported(

0 commit comments

Comments
 (0)