Skip to content

Fix elision of long collections in assertion messages with -vv#14748

Open
Zac-HD wants to merge 1 commit into
pytest-dev:mainfrom
Zac-HD:claude/pytest-pr-12322-issues-t30zxt
Open

Fix elision of long collections in assertion messages with -vv#14748
Zac-HD wants to merge 1 commit into
pytest-dev:mainfrom
Zac-HD:claude/pytest-pr-12322-issues-t30zxt

Conversation

@Zac-HD

@Zac-HD Zac-HD commented Jul 21, 2026

Copy link
Copy Markdown
Member

The message part of assert cond, msg went through saferepr(obj, maxsize), where -vv maps to maxsize=None. That lifts the overall string-length cap, but SafeRepr still inherits reprlib's per-container limits (maxlist=6 etc.), so e.g. assert False, dir("") stayed elided with ... at any verbosity — the exact reproducer from issue #12307, which #12662 only partially fixed (it covered long scalar reprs but not collections).

Use the _saferepr helper instead, as originally proposed in #12322: it routes maxsize=None to saferepr_unlimited(), which uses a plain repr(), matching how asserted expressions are already displayed at high verbosity.

Closes #12322.

The message part of `assert cond, msg` went through
`saferepr(obj, maxsize)`, where `-vv` maps to `maxsize=None`. That lifts
the overall string-length cap, but `SafeRepr` still inherits reprlib's
per-container limits (`maxlist=6` etc.), so e.g. `assert False, dir("")`
stayed elided with `...` at any verbosity — the exact reproducer from
issue pytest-dev#12307, which pytest-dev#12662 only partially fixed (it covered long scalar
reprs but not collections).

Use the `_saferepr` helper instead, as originally proposed in pytest-dev#12322:
it routes `maxsize=None` to `saferepr_unlimited()`, which uses a plain
`repr()`, matching how asserted expressions are already displayed at
high verbosity.

Closes pytest-dev#12322
Fixes pytest-dev#12307

Co-authored-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QgcKk5Az2fxFFfEP2tQ9Sk
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jul 21, 2026
@Zac-HD
Zac-HD enabled auto-merge (squash) July 21, 2026 19:55
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