File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -7,8 +7,10 @@ UNRELEASED
7
7
*UNRELEASED *
8
8
9
9
* Print output "dots" for successful unittest subtests (`#164 `_).
10
+ * Improved reporting in case subtests raise `pytest.xfail ` (`#194 `_).
10
11
11
12
.. _#164 : https://github.com/pytest-dev/pytest-subtests/issues/164
13
+ .. _#194 : https://github.com/pytest-dev/pytest-subtests/pull/194
12
14
13
15
0.14.1
14
16
------
Original file line number Diff line number Diff line change @@ -457,12 +457,26 @@ def pytest_report_teststatus(
457
457
if report .when != "call" or not isinstance (report , SubTestReport ):
458
458
return None
459
459
460
- if hasattr (report , "wasxfail" ):
461
- return None
462
-
463
460
outcome = report .outcome
464
461
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 :
466
480
short = "" if config .option .no_subtests_shortletter else ","
467
481
return f"subtests { outcome } " , short , f"{ description } SUBPASS"
468
482
elif report .skipped :
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ def test_foo(subtests):
131
131
pytest .importorskip ("xdist" )
132
132
result = pytester .runpytest ("-n1" )
133
133
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 *" ]
135
135
result .stdout .fnmatch_lines (expected_lines )
136
136
137
137
def test_typing_exported (
You can’t perform that action at this time.
0 commit comments