- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.9k
 
          Fix diff output for data types where -v would show less information
          #9661
        
          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
Conversation
`_compare_eq_verbose` doesn't seem to useful in the end, with the examples we have in the test suite. Close pytest-dev#5192
| if not verbose and not running_on_ci(): | ||
| return ["Use -v to get the full diff"] | ||
| if verbose <= 0 and not running_on_ci(): | ||
| return ["Use -v to get more diff"] | 
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 "full diff" here is misleading, because the users would use -v, and in the next run we show Use -vv to get the full diff again if the output is too large.
| 
           @nicoddemus Yes, this is much better. This resolves the issue seen earlier. I'm currently testing various assertion combinations, and so far this change seems to have the desired outcome.  | 
    
| @@ -0,0 +1,3 @@ | |||
| Fixed test output for some data types where ``-v`` would show less information. | |||
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.
Marked this as an "improvement", but arguably this can be considered a bugfix.
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.
TL;DR - LGTM :)
IIUC the situation is this:
- Assertion rewrite calls the reprcompare mechanism, with custom "expls" for the assertion (the rewrite special sauce)
 - But before using these special expls, it also calls the 
pytest_assertrepr_comparehook to see if it wants to offer its own formatting (which is preferred). The hook only gets the op and values (no special stringification sauce). - The built-in 
pytest_assertrepr_comparehookimpl in this case eventually reaches_compare_eq_any. 
Without verbose, _compare_eq_any returns None for this, and the custom expls are used.
With verbose, before this fix, _compare_eq_verbose would be called, which ends up with
- Less nice formatting, because no special sauce.
 - Less verbose than the expls, because no special sauce, only shows the actual values.
 
This PR removes _compare_eq_verbose so it falls back to the rewrite expls.
So I looked into why _compare_eq_any was added in the first place. AFAIU, it used to be that the rewrite formatting didn't take verbosity in account when truncating - it always truncated. So _compare_eq_any was added as a workaround. But the underlying problem has since been fixed by @nicoddemus in be8d63e. So this is probably no longer needed.
| 
           Thanks @bluetech for looking into why  Do you agree this is an improvement, or should we treat it as bug fix and backport to 7.0.x?  | 
    
| 
           I think the compare-any is an improvement, I wouldn't backport it since it's not risk-free either. The  We probably shouldn't wait too long with pytest 7.1 though. I will open an issue for a release schedule.  | 
    
_compare_eq_verbosedoesn't seem to useful in the end, with the examples wehave in the test suite.
Close #5192
cc @mdmintz