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

Add distinct option to show full (assertion) diffs always #3962

Closed
blueyed opened this issue Sep 10, 2018 · 9 comments
Closed

Add distinct option to show full (assertion) diffs always #3962

blueyed opened this issue Sep 10, 2018 · 9 comments
Labels
type: enhancement new feature or API change, should be merged into features branch

Comments

@blueyed
Copy link
Contributor

blueyed commented Sep 10, 2018

Currently you have to use -vv to show the whole diff for dicts, and not to truncate in general.

Code:

  1. there should be a distinct option additionally, because I usually have to re-run the test with -vv then, but would rather have it by default - without using very verbose mode by default

  2. pytest.assertion.truncate checks if it is running on CI and enables this then always. This should also be done for comparing dicts anyway. Should I file a separate issue / create a PR for this already?

I would like to add this to the config file for projects where it makes sense, e.g. https://github.com/Vimjas/covimerage, where most of the tests are comparing program output (by lines), which usually gets truncated.
-vv would still have the same effect of course.

@blueyed blueyed added the type: enhancement new feature or API change, should be merged into features branch label Sep 10, 2018
@cheezman34
Copy link

A potential workaround that might work for some:

Add to your conftest.py

from _pytest.assertion.util import assertrepr_compare
def pytest_assertrepr_compare(config, op, left, right):
    # hack the verbosity so we always show full diffs on assertion failures,
    # even if we're otherwise not fully verbose
    config.option.verbose = 2
    return assertrepr_compare(config, op, left, right)

@blueyed
Copy link
Contributor Author

blueyed commented Apr 17, 2019

The hack does not for truncation via saferepr unfortunately (for a overlong assertion message itself).

See also #2382 and #3693.

This is really frustrating, but at least --assert=plain can be used to get the full assertion message.

blueyed added a commit to blueyed/pytest that referenced this issue Oct 21, 2019
TODO:

- [ ] real plugin hook?
- [ ] should handle other places where safeformat is used also, via
      args/options to the hook then likely.

Ref: pytest-dev#3962
Ref: pytest-dev#5933
@blueyed
Copy link
Contributor Author

blueyed commented Oct 21, 2019

@pytest-dev/contributors
Any input on this (given that there are already some WIP PRs to fix issues in this regard), please?

@blueyed
Copy link
Contributor Author

blueyed commented Nov 3, 2019

btw/JFI: for skipping truncation (just one part of it), you can use CI=true as a workaround:

def _should_truncate_item(item):
"""
Whether or not this test item is eligible for truncation.
"""
verbose = item.config.option.verbose
return verbose < 2 and not _running_on_ci()
def _running_on_ci():
"""Check if we're currently running on a CI system."""
env_vars = ["CI", "BUILD_NUMBER"]
return any(var in os.environ for var in env_vars)

blueyed added a commit to blueyed/pytest that referenced this issue Nov 3, 2019
blueyed added a commit to blueyed/pytest that referenced this issue Nov 3, 2019
@nicoddemus
Copy link
Member

Any input on this (given that there are already some WIP PRs to fix issues in this regard), please?

I guess they are being discussed in each PR? If not, please feel free to ping any stale PRs.

@blueyed blueyed closed this as completed Nov 27, 2019
@blueyed blueyed reopened this Feb 13, 2020
l0b0 added a commit to linz/geostore that referenced this issue Jan 19, 2021
This makes test output much better, at the cost of a bunch of unwanted
verbosity. See <pytest-dev/pytest#3962>.
l0b0 added a commit to linz/geostore that referenced this issue Jan 19, 2021
This makes test output much better, at the cost of a bunch of unwanted
verbosity. See <pytest-dev/pytest#3962>.
l0b0 added a commit to linz/geostore that referenced this issue Jan 19, 2021
This makes test output much better, at the cost of a bunch of unwanted
verbosity. See <pytest-dev/pytest#3962>.
l0b0 added a commit to linz/geostore that referenced this issue Jan 20, 2021
This makes test output much better, at the cost of a bunch of unwanted
verbosity. See <pytest-dev/pytest#3962>.
l0b0 added a commit to linz/geostore that referenced this issue Jan 20, 2021
This makes test output much better, at the cost of a bunch of unwanted
verbosity. See <pytest-dev/pytest#3962>.
l0b0 added a commit to linz/geostore that referenced this issue Jan 21, 2021
This makes test output much better, at the cost of a bunch of unwanted
verbosity. See <pytest-dev/pytest#3962>.
l0b0 added a commit to linz/geostore that referenced this issue Jan 21, 2021
This makes test output much better, at the cost of a bunch of unwanted
verbosity. See <pytest-dev/pytest#3962>.
l0b0 added a commit to linz/geostore that referenced this issue Jan 21, 2021
This makes test output much better, at the cost of a bunch of unwanted
verbosity. See <pytest-dev/pytest#3962>.
l0b0 added a commit to linz/geostore that referenced this issue Jan 25, 2021
This makes test output much better, at the cost of a bunch of unwanted
verbosity. See <pytest-dev/pytest#3962>.
@bwoodsend
Copy link

This is closed by 56d9ea0 is it not? You can now just pop assert_truncate_level=0 into the pytest.ini and never end up on the wrong end of the Full output truncated message again.

@asottile
Copy link
Member

@bwoodsend that commit is not in pytest, but in a fork

@bwoodsend
Copy link

🤦 So it is...

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pytest that referenced this issue Dec 14, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pytest that referenced this issue Dec 14, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pytest that referenced this issue Dec 14, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pytest that referenced this issue Jun 7, 2023
@Pierre-Sassoulas
Copy link
Member

Done in #11473

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants