Use pytest's pretty-printer for pformat outputs (expand-style format) - #14886
Draft
aryansk wants to merge 1 commit into
Draft
Use pytest's pretty-printer for pformat outputs (expand-style format)#14886aryansk wants to merge 1 commit into
pformat outputs (expand-style format)#14886aryansk wants to merge 1 commit into
Conversation
Adopt the expanded pretty-printed format (as introduced by pprint's `expand` option in Python 3.15) for the warnings summary in pytest.warns failures, approx error messages, and the full local-variable listing in tracebacks, by formatting them with pytest's own pretty-printer instead of the stdlib pprint.pformat. The output is now uniform across all supported Python versions, instead of only changing once Python 3.15 becomes the runtime. Closes pytest-dev#14859 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
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.
Fixes #14859
What
Adopts the expanded pretty-printed format (the style Python 3.15 introduces via the
expandoption ofpprint.pformat) for the diagnostic messages that pytest formats with the stdlib pretty-printer, by using pytest's own_pytest._io.pprintinstead — the direction suggested by @bluetech and @Pierre-Sassoulas in the issue thread.Adds a small
pformat()convenience entry point to_pytest/_io/pprint.py(mirroring the stdlib signature, minuscompact/sort_dicts/underscore_numbers) and switches three call sites to it:recwarn— the "Emitted warnings:" summary inpytest.warns(...)failure messages (pformat([...], indent=2)).approx— the "full mapping / full sequence" detail in the nested-approxTypeErrormessages.saferepr.safeformat— the full local-variable listing in tracebacks (--showlocalswith--tb=long,truncate_locals=False).Because pytest's printer always expands containers, the output is now uniform across all supported Python versions — previously it would have silently changed once Python 3.15's
expandoption became the norm.Why not the other
pprint.pformatcall sites?The comparator summaries in
_pytest/assertion/_compare_mapping.py(and the--cache-showvalue display) keep the stdlib printer on purpose:_compare_mappingbuilds its "Common items"/"Left contains N more items" sub-dicts from set iteration, and the stdlib printer's key-sorting is what keeps that output deterministic. pytest's printer doesn't sort, so switching those would make assertion output depend on hash randomization.--cache-showis a stable CLI display; changing its format is out of scope here.Testing
pformathelper intesting/io/test_pprint.py(expansion, indent, and uniformity across the versions pytest supports).testing/test_recwarn.py,testing/code/test_excinfo.py) to the new uniform format.4305 passed, 125 skipped, 12 xfailed(with--ignore=testing/plugins_integration);ruffclean on the changed files.