Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ Roland Puntaier
Romain Dorgueil
Roman Bolshakov
Ronny Pfannschmidt
Roqia Salah
Ross Lawley
Ruaridh Williamson
Russel Winder
Expand Down
2 changes: 2 additions & 0 deletions changelog/6997.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
XFAIL reports from teardown phases now include the phase in the short test
summary.
7 changes: 6 additions & 1 deletion src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,12 @@ def show_xfailed(lines: list[str]) -> None:
)
markup_word = self._tw.markup(verbose_word, **verbose_markup)
nodeid = _get_node_id_with_markup(self._tw, self.config, rep)
line = f"{markup_word} {nodeid}"

if rep.when == "teardown":
line = f"{markup_word} at teardown of {nodeid}"
else:
line = f"{markup_word} {nodeid}"

reason = rep.wasxfail
if reason:
line += " - " + str(reason)
Expand Down
27 changes: 27 additions & 0 deletions testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,33 @@ def test_func():
result = pytester.runpytest()
result.stdout.fnmatch_lines(["*1 xfail*"])

def test_xfail_call_and_teardown_reports_show_phase(
self, pytester: Pytester
) -> None:
pytester.makepyfile(
test_case="""
import pytest

@pytest.fixture
def my_fix():
yield
raise Exception("teardown")

@pytest.mark.xfail(reason="Some reason")
def test_func(my_fix):
raise Exception("call")
"""
)

result = pytester.runpytest("-rx")

result.stdout.fnmatch_lines(
[
"*XFAIL*test_case.py::test_func*",
"*XFAIL at teardown of*test_case.py::test_func*",
]
)


class TestSkip:
def test_skip_class(self, pytester: Pytester) -> None:
Expand Down