-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Show full repr with assert a==b and -vv #4607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Show full repr with ``assert a==b`` and ``-vv``. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,8 @@ def isiterable(obj): | |
| elif type(left) == type(right) and (isdatacls(left) or isattrs(left)): | ||
| type_fn = (isdatacls, isattrs) | ||
| explanation = _compare_eq_cls(left, right, verbose, type_fn) | ||
| elif verbose: | ||
| explanation = _compare_eq_verbose(left, right) | ||
| if isiterable(left) and isiterable(right): | ||
| expl = _compare_eq_iterable(left, right, verbose) | ||
| if explanation is not None: | ||
|
|
@@ -236,6 +238,18 @@ def escape_for_readable_diff(binary_text): | |
| return explanation | ||
|
|
||
|
|
||
| def _compare_eq_verbose(left, right): | ||
| keepends = True | ||
| left_lines = repr(left).splitlines(keepends) | ||
| right_lines = repr(right).splitlines(keepends) | ||
|
|
||
| explanation = [] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay I've removed that now |
||
| explanation += [u"-" + line for line in left_lines] | ||
| explanation += [u"+" + line for line in right_lines] | ||
|
|
||
| return explanation | ||
|
|
||
|
|
||
| def _compare_eq_iterable(left, right, verbose=False): | ||
| if not verbose: | ||
| return [u"Use -v to get the full diff"] | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses it with
-valready, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That's also what happens in the case of e.g. strings: https://github.com/pytest-dev/pytest/blob/master/src/_pytest/assertion/util.py#L176
The filtering based on -vv happens down the line somewhere else (in all cases).
So with -v this function will generate full output but pytest won't ultimately show the whole of it unless -vv is given.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's confusing - especially when looking at the test.
Can this be fixed here (in this PR) also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is showing the output of
call_equalwhich calls these functions directly. Shortening (without -vv) takes place here I think: https://github.com/pytest-dev/pytest/blob/master/src/_pytest/assertion/truncate.pyThat looks like a deliberate design and seems reasonable to me so I'm not sure what needs fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense that truncation happens later down the line, otherwise every implementation would need to implement or call truncation (IIUC).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yeah, I was also confused for this same reason, I had to look at the rest of the code to understand what was going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicoddemus
I think we should create a follow-up issue/PR for this.
Have you looked closer at it already?