Repository navigation
fix: preserve nested mapping values in assertion diffs - #15222
Closed
rudra337-lgtm wants to merge 2 commits into
Closed
rudra337-lgtm wants to merge 2 commits into
rudra337-lgtm wants to merge 2 commits into
Conversation
ege-arhan
reviewed
Oct 19, 2026
ege-arhan
left a comment
There was a problem hiding this comment.
When differing mapping values wrap across multiple lines (e.g. nested lists or dictionaries with 10+ items exceeding pprint width), highlighter(left_repr) + " != " + highlighter(right_repr) glues != directly onto the last line of left_repr and embeds unhandled \n characters:
d1 = {"key": [f"item_{i}" for i in range(15)]}
d2 = {"key": [f"item_{i}" for i in range(14)] + ["diff"]}
# asserting d1 == d2 formats as:
# {key: [item_0,
# ...,
# item_14]} != {key: [item_0,
# ...,
# diff]}Here the closing bracket of the left mapping shares a line with != and the first line of the right mapping, and the raw newlines bypass terminal reporter line prefixing/indentation. If multiline pretty-printing is introduced here, differing items should either split lines cleanly across separate blocks or preserve single-line rendering.
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.
What was wrong
When an assertion compared mappings whose differing values were lists, pytest used
safereprfor the entire one-item mapping. Its nested repr truncation could hide the actual differing list element, even for a short eight-item list.What changed
Render differing mapping entries with
pprint.pformat, retaining the existing safe-repr fallback when formatting user objects raises. Added a regression test for the reported nested-list case.Verification
[1, 1, 1, 1, 1, 1, ...]on both sides.2 passed, 207 deselected.git diff --checkpassed.Fixes #11980