Skip to content

Show the phase of errors in the short test summary - #15317

Open
doubledare704 wants to merge 3 commits into
pytest-dev:mainfrom
doubledare704:short-summary-error-phase
Open

doubledare704 wants to merge 3 commits into
pytest-dev:mainfrom
doubledare704:short-summary-error-phase

Conversation

@doubledare704

@doubledare704 doubledare704 commented Nov 1, 2026 •

Copy link
Copy Markdown

Refs #1004.

ERROR entries in the short test summary don't say which phase they came from. For a test whose call passed but whose teardown raised, -rE shows:

ERROR test_repro.py::test_ok - ValueError: boom in teardown

which, next to 1 passed, 1 error, makes it look like a different test errored. show_xfailed already renders XFAIL at teardown of <nodeid>; this does the same for errors coming from _get_line_with_reprcrash_message:

FAILED test_repro.py::test_bad - assert 0
ERROR at teardown of test_repro.py::test_ok - ValueError: boom in teardown
ERROR at teardown of test_repro.py::test_bad - ValueError: boom in teardown
ERROR at setup of test_repro.py::test_s - ValueError: boom in setup

This is the first prerequisite listed in #1004 (comment). Counts are unchanged; only the summary line text changes. Call failures and collection errors render exactly as before (the prefix is only added for setup/teardown).

Things worth a look in review:

  • Anything parsing ERROR <nodeid> out of the short summary will now see ERROR at <phase> of <nodeid>. Hence improvement rather than bugfix; happy to change the category if you'd prefer to flag it more strongly.
  • The longer prefix leaves less room for the reprcrash message at narrow widths, so it gets truncated sooner. test_teardown_with_test_also_failing now only matches the line prefix for that reason.

Added test_error_extra_reporting_shows_phase and updated the two existing expectations in test_terminal.py and acceptance_test.py.

  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • If AI agents were used, they are credited in Co-authored-by commit trailers.
  • Create a new changelog file in the changelog directory.
  • Add yourself to AUTHORS in alphabetical order.

🤖 Generated with Claude Code

Why this change adds the phase only for setup and teardown?

A failed call is always reported as FAILED and a failed setup/teardown as ERROR (default pytest_report_teststatus), so FAILED already implies the phase while ERROR was ambiguous between setup and teardown. It also matches the existing ERROR at {when} of header in the ERRORS section and the XFAIL summary format, and leaves FAILED lines (the most commonly parsed) untouched.

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 <phase> of",
matching how XFAIL entries are already rendered.

Refs pytest-dev#1004

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chiragjangiir chiragjangiir left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: Show the phase of errors in the short test summary (#15317)

1. Summary & Architecture

Enhances Pytest terminal reporting by explicitly displaying the lifecycle phase (setup, call, teardown) for test failures in the short test summary section.

2. Implementation & Diff Analysis

  • Terminal Reporter Enhancement: In src/_pytest/terminal.py, formats error report lines in build_summary_stats() to include [setup], [teardown], or [call] when errors occur outside the primary test execution phase.
  • Visual Distinction: Helps developers instantly determine whether a failure originated in fixture setup/teardown versus the test body itself.

3. Edge Cases & Robustness

  • Omits phase label for standard call phase failures to preserve existing compact output conventions where redundant.
  • Maintains full compatibility with custom terminal reporters and JUnit XML outputs.

4. Test Coverage Assessment

  • Adds unit tests in testing/test_terminal.py testing terminal output formatting for setup and teardown fixture exceptions.

5. Recommendation

Outstanding reporting clarity improvement for complex test suites with heavy fixture usage.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants