From 1387de3cae4415f2b1a5c3c1f8abaf003377c2ef Mon Sep 17 00:00:00 2001 From: Oleksii Date: Sun, 1 Nov 2026 18:43:23 +0200 Subject: [PATCH 1/2] Show the phase of errors in the short test summary ERROR entries in the short test summary did not say whether the error happened in setup or teardown, so a teardown error of a passing test showed up as a bare "ERROR test_foo". Prefix them with "at of", matching how XFAIL entries are already rendered. Refs #1004 Co-Authored-By: Claude Opus 5.5 --- changelog/1004.improvement.rst | 1 + src/_pytest/terminal.py | 6 ++++- testing/acceptance_test.py | 4 ++-- testing/test_terminal.py | 41 +++++++++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 changelog/1004.improvement.rst diff --git a/changelog/1004.improvement.rst b/changelog/1004.improvement.rst new file mode 100644 index 00000000000..3bcd85ae6f6 --- /dev/null +++ b/changelog/1004.improvement.rst @@ -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. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 00ef7d3cddb..a03c602379c 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -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 diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 3983bd0007d..9a2ec159631 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -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 * =*", ] ) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 21b0557a470..4a43b313059 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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") @@ -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", ] ) From 8933d1c9701141783c0dc7f215fd1b6e43c769c2 Mon Sep 17 00:00:00 2001 From: Oleksii Date: Sun, 1 Nov 2026 19:05:07 +0200 Subject: [PATCH 2/2] Add myself to AUTHORS Co-Authored-By: Claude Opus 5.5 --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 136ffd6c5ee..ec70ec8adba 100644 --- a/AUTHORS +++ b/AUTHORS @@ -375,6 +375,7 @@ Nipunn Koorapati Oleg Pidsadnyi Oleg Sushchenko Oleksandr Zavertniev +Oleksii Ovdiienko Olga Matoula Oliver Bestwalter Olivier Grisel