Skip to content
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

Fix diff output for data types where -v would show less information #9661

Merged
merged 1 commit into from Feb 15, 2022

Conversation

nicoddemus
Copy link
Member

_compare_eq_verbose doesn't seem to useful in the end, with the examples we
have in the test suite.

Close #5192

cc @mdmintz

`_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"]
Copy link
Member Author

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.

@mdmintz
Copy link

mdmintz commented Feb 10, 2022

@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.
Copy link
Member Author

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.

Copy link
Member

@bluetech bluetech left a 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_compare hook 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_compare hookimpl 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

  1. Less nice formatting, because no special sauce.
  2. 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.

@nicoddemus
Copy link
Member Author

Thanks @bluetech for looking into why _compare_eq_verbose existed in the first place. 😁

Do you agree this is an improvement, or should we treat it as bug fix and backport to 7.0.x?

@bluetech
Copy link
Member

I think the compare-any is an improvement, I wouldn't backport it since it's not risk-free either.

The -q is a bugfix, can backport if you feel like it :)

We probably shouldn't wait too long with pytest 7.1 though. I will open an issue for a release schedule.

@nicoddemus nicoddemus merged commit fac8f28 into pytest-dev:main Feb 15, 2022
@nicoddemus nicoddemus deleted the fix-verbosity-5192 branch February 15, 2022 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed test output is less verbose with -v than not using -v
3 participants