Cap text diff computation for huge strings in non-verbose mode#14749
Closed
Zac-HD wants to merge 1 commit into
Closed
Cap text diff computation for huge strings in non-verbose mode#14749Zac-HD wants to merge 1 commit into
Zac-HD wants to merge 1 commit into
Conversation
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
Member
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 :) |
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. |
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.
At the default verbosity the displayed assertion explanation is truncated to a handful of lines, but
_diff_textalways randifflib.ndiffover 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-vto get the full diff. This mirrors the existing behaviour of skipping identical leading/trailing characters unless-vis given, and the precedent of_compare_eq_iterablenot 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