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 @@ -375,6 +375,7 @@ Nipunn Koorapati
Oleg Pidsadnyi
Oleg Sushchenko
Oleksandr Zavertniev
Oleksii Ovdiienko
Olga Matoula
Oliver Bestwalter
Olivier Grisel
Expand Down
1 change: 1 addition & 0 deletions changelog/1004.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Errors in the short test summary (``-rE``) now mention the phase they occurred in, for example ``ERROR at teardown of test_foo.py::test_foo``, matching how ``XFAIL`` entries are already displayed.
6 changes: 5 additions & 1 deletion src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,11 @@ def _get_line_with_reprcrash_message(
word = tw.markup(verbose_word, **verbose_markup)
node = _get_node_id_with_markup(tw, config, rep)

line = f"{word} {node}"
when = getattr(rep, "when", None)
if when in ("setup", "teardown"):
line = f"{word} at {when} of {node}"
else:
line = f"{word} {node}"
line_width = wcswidth(line)

msg: str | None
Expand Down
4 changes: 2 additions & 2 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1762,8 +1762,8 @@ def test_fail_call():
[
"=* short test summary info =*",
"FAILED test_it.py::test_fail_call - StopIteration: 3",
"ERROR test_it.py::test_fail_setup - StopIteration: 1",
"ERROR test_it.py::test_fail_teardown - StopIteration: 2",
"ERROR at setup of test_it.py::test_fail_setup - StopIteration: 1",
"ERROR at teardown of test_it.py::test_fail_teardown - StopIteration: 2",
"=* 1 failed, 1 passed, 2 errors in * =*",
]
)
41 changes: 40 additions & 1 deletion testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,44 @@ def test_fail_extra_reporting(
)


def test_error_extra_reporting_shows_phase(pytester: Pytester) -> None:
"""Errors in the short test summary mention the phase they happened in (#1004)."""
pytester.makepyfile(
"""
import pytest

@pytest.fixture
def bad_setup():
raise ValueError("setup")

@pytest.fixture
def bad_teardown():
yield
raise ValueError("teardown")

def test_setup(bad_setup):
pass

def test_teardown(bad_teardown):
pass

def test_both(bad_teardown):
assert 0
"""
)
result = pytester.runpytest("-rfE", "-vv")
result.stdout.fnmatch_lines(
[
"*short test summary*",
"FAILED test_error_extra_reporting_shows_phase.py::test_both - assert 0",
"ERROR at setup of test_error_extra_reporting_shows_phase.py::test_setup - ValueError: setup",
"ERROR at teardown of test_error_extra_reporting_shows_phase.py::test_teardown - ValueError: teardown",
"ERROR at teardown of test_error_extra_reporting_shows_phase.py::test_both - ValueError: teardown",
"*1 failed, 1 passed, 3 errors*",
]
)


def test_fail_reporting_on_pass(pytester: Pytester) -> None:
pytester.makepyfile("def test_this(): assert 1")
result = pytester.runpytest("-rf")
Expand Down Expand Up @@ -2654,7 +2692,8 @@ def test_foo(fail_teardown):
[
r"test_teardown_with_test_also_failing.py FE\s+\[100%\]",
"FAILED test_teardown_with_test_also_failing.py::test_foo - assert 0",
"ERROR test_teardown_with_test_also_failing.py::test_foo - assert False",
# The added phase makes the line too long for the reprcrash message.
"ERROR at teardown of test_teardown_with_test_also_failing.py::test_foo",
]
)

Expand Down
Loading