Skip to content

Trim short test summary lines to the terminal width when color is enabled - #15216

Open
LemonCondor wants to merge 2 commits into
pytest-dev:mainfrom
LemonCondor:fix/short-summary-color-width
Open

LemonCondor wants to merge 2 commits into
pytest-dev:mainfrom
LemonCondor:fix/short-summary-color-width

Conversation

@LemonCondor

Copy link
Copy Markdown

When color output is enabled, lines in the short test summary can exceed the terminal width because ANSI color codes distort the width calculation. This change strips color codes before measuring line widths and adds a regression test comparing colored and uncolored output.

Reproduce: a test failing with a long message (assert 0, "x" * 300), run with COLUMNS=80 pytest -rf --color=yes: the FAILED ... summary line is wider than 80 columns, while with --color=no it is trimmed to 80.

  • 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. (AI assistance: Claude Code; credited in the commit trailer.)
  • Create a new changelog file in the changelog directory.
  • Add yourself to AUTHORS in alphabetical order.

_get_line_with_reprcrash_message() measured the "FAILED <nodeid>" prefix
with wcswidth() after markup was applied. The ANSI escape codes are
control characters, so wcswidth() returned -1 and the message was
trimmed to the full terminal width plus one column, making every
colored summary line overflow by the width of its prefix.

Strip the escape sequences before measuring the prefix.
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 19, 2026
Co-authored-by: Claude <noreply@anthropic.com>

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