Fix elision of long collections in assertion messages with -vv#14748
Open
Zac-HD wants to merge 1 commit into
Open
Fix elision of long collections in assertion messages with -vv#14748Zac-HD wants to merge 1 commit into
Zac-HD wants to merge 1 commit into
Conversation
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
Zac-HD
enabled auto-merge (squash)
July 21, 2026 19:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The message part of
assert cond, msgwent throughsaferepr(obj, maxsize), where-vvmaps tomaxsize=None. That lifts the overall string-length cap, butSafeReprstill inherits reprlib's per-container limits (maxlist=6etc.), 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
_safereprhelper instead, as originally proposed in #12322: it routesmaxsize=Nonetosaferepr_unlimited(), which uses a plainrepr(), matching how asserted expressions are already displayed at high verbosity.Closes #12322.