Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions changelog/14523.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Assertion explanations are now built lazily and the truncator stops
the comparison helpers as soon as it has enough output, so comparing
two large collections no longer builds the full diff in order to
discard it. A focused micro-benchmark the worst case scenario
(``set(range(500_000)) == set(range(1, 500_001))``) drops from ~2,200 ms
to ~43 ms; but realistic test suite with mostly small diffs should be
unchanged.

String comparisons (the ``ndiff`` diff style) are bounded the same way:
``difflib.ndiff`` computes the whole diff up front and cannot be
short-circuited by streaming, so its inputs are capped to the truncation
budget instead. A large ``str == str`` mismatch that previously spent
seconds in ``ndiff`` is now near-instant. When truncating, the diff
reflects a local alignment of the bounded prefix, which can differ from
the full diff for wholly-dissimilar inputs; use ``-vv`` for the exact
full diff.

A dict comparison with many keys only on one side ("Left/Right contains
N more items") no longer pretty-prints the whole extra subdict when it is
going to be truncated: past the budget it shows the smallest few keys one
per line instead. Small comparisons are unchanged (the compact block).

The truncation footer no longer reports the hidden-line count
(``...Full output truncated (N lines hidden), ...`` becomes
``...Full output truncated, ...``); diff lines now carry a redundant
``\x1b[0m`` reset prefix (invisible to terminals) so we can handle
line one by one.
2 changes: 1 addition & 1 deletion doc/en/example/reportingdemo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
E 1
E 1...
E
E ...Full output truncated (7 lines hidden), use '-vv' to show
E ...Full output truncated, use '-vv' to show

failure_demo.py:62: AssertionError
_________________ TestSpecialisedExplanations.test_eq_list _________________
Expand Down
4 changes: 2 additions & 2 deletions doc/en/how-to/output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Now we can increase pytest's verbosity:
E 'banana',
E 'apple',...
E
E ...Full output truncated (7 lines hidden), use '-vv' to show
E ...Full output truncated, use '-vv' to show
test_verbosity_example.py:8: AssertionError
____________________________ test_numbers_fail _____________________________
Expand All @@ -190,7 +190,7 @@ Now we can increase pytest's verbosity:
E {'10': 10, '20': 20, '30': 30, '40': 40}
E ...
E
E ...Full output truncated (16 lines hidden), use '-vv' to show
E ...Full output truncated, use '-vv' to show
test_verbosity_example.py:14: AssertionError
___________________________ test_long_text_fail ____________________________
Expand Down
Loading
Loading