FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cap text diff computation for huge strings in non-verbose mode by Zac-HD · Pull Request #14749 · pytest-dev/pytest · GitHub

Cap text diff computation for huge strings in non-verbose mode - #14749

Closed
Zac-HD wants to merge 1 commit into
pytest-dev:mainfrom
Zac-HD:claude/pytest-issue-12406-l9uasm
Closed

Cap text diff computation for huge strings in non-verbose mode#14749
Zac-HD wants to merge 1 commit into
pytest-dev:mainfrom
Zac-HD:claude/pytest-issue-12406-l9uasm

Conversation

Zac-HD commented Jul 21, 2026

Copy link
Copy Markdown
Member

At the default verbosity the displayed assertion explanation is truncated to a handful of lines, but _diff_text always ran difflib.ndiff over the full strings first. For multi-million-line strings this could take hours (difflib's runtime blows up on large inputs), only for almost all of the output to be discarded.

Now, when verbose < 1, the diff is computed over at most the first 100 lines of each side (after the existing identical leading/trailing character skipping), with a message pointing at -v to get the full diff. This mirrors the existing behaviour of skipping identical leading/trailing characters unless -v is given, and the precedent of _compare_eq_iterable not computing a full diff at low verbosity.

The message starts with "Skipping" so that _notin_text's existing filtering drops it there, like the other skip hints.

Fixes #12406

At the default verbosity the displayed assertion explanation is
truncated to a handful of lines, but ``_diff_text`` always ran
``difflib.ndiff`` over the full strings first. For multi-million-line
strings this could take hours (difflib's runtime blows up on large
inputs), only for almost all of the output to be discarded.

Now, when ``verbose < 1``, the diff is computed over at most the first
100 lines of each side (after the existing identical leading/trailing
character skipping), with a message pointing at ``-v`` to get the full
diff. This mirrors the existing behaviour of skipping identical
leading/trailing characters unless ``-v`` is given, and the precedent
of ``_compare_eq_iterable`` not computing a full diff at low verbosity.

The message starts with "Skipping" so that ``_notin_text``'s existing
filtering drops it there, like the other skip hints.

Fixes pytest-dev#12406

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVRWXxfTLrU4B95jeoeuHN
Zac-HD requested a review from RonnyPfannschmidt July 21, 2026 17:27
psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jul 21, 2026

Pierre-Sassoulas commented Jul 21, 2026
edited
Loading

Copy link
Copy Markdown
Member

More conservative approach than #14543 that keep the exact output even when it would take a lot of time to generate ? (Might not fix #8998)

Copy link
Copy Markdown
Member

Also, if you're interested in making assertion message faster there's also #14523 that is very impactful on everything but the ndiff part when the verbosity is low and the assert message will be truncated :)

Zac-HD commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

Closing this in favor of #14543; my patch would not handle the case of very long individual lines, and I'm happy to defer to work already in flight.

Zac-HD closed this Jul 21, 2026
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

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

text diffs on huge files are slow

3 participants


Back | FazBrowse Home | New Git URL