How do I get PyCharm to show entire error diffs from pytest?

Had a look in the pytest code base and maybe you can try some of these out:

1) Set verbosity level in the test execution:

./app_main --pytest --verbose test-suite/

2) Add environment variable for "CI" or "BUILD_NUMBER". In the link to the truncate file you can see that these env variables are used to determine whether or not the truncation block is run.

import os

os.environ["BUILD_NUMBER"] = '1'
os.environ["CI"] = 'CI_BUILD'

3) Attempt to set DEFAULT_MAX_LINES and DEFAULT_MAX_CHARS on the truncate module (Not recommending this since it uses a private module):

from _pytest.assertion import truncate

truncate.DEFAULT_MAX_CHARS = 1000
truncate.DEFAULT_MAX_LINES = 1000

According to the code the -vv option should work so it's strange that it's not for you:

Current default behaviour is to truncate assertion explanations at ~8 terminal lines, unless running in "-vv" mode or running on CI.

Pytest truncation file which are what I'm basing my answers off of: pytest/truncate.py

Hope something here helps you!


If you look closely into PyCharm sources, from the whole pytest output, PyCharm uses a single line the to parse the data for displaying in the Click to see difference dialog. This is the AssertionError: <message> line:

def test_spam():
>       assert v1 == v2
E       AssertionError: assert {'foo': 'bar'} == {'foo': 'baz'}
E         Differing items:
E         {'foo': 'bar'} != {'foo': 'baz'}
E         Use -v to get the full diff

If you want to see the full diff line without truncation, you need to customize this line in the output. For a single test, this can be done by adding a custom message to the assert statement:

def test_eggs():
    assert a == b, '{0} != {1}'.format(a, b)

If you want to apply this behaviour to all tests, define custom pytest_assertrepr_compare hook. In the conftest.py file:

# conftest.py
def pytest_assertrepr_compare(config, op, left, right):
    if op in ('==', '!='):
        return ['{0} {1} {2}'.format(left, op, right)]

The equality comparison of the values will now still be stripped when too long; to show the complete line, you still need to increase the verbosity with -vv flag.

Now the equality comparison of the values in the AssertionError line will not be stripped and the full diff is displayed in the Click to see difference dialog, highlighting the diff parts:

enter image description here


Being that pytest integrates with unittest, as a workaround you may be able to set it up as a unittest and then set Test.maxDiff = None or per each specific test self.maxDiff = None

https://docs.pytest.org/en/latest/index.html

Can run unittest (including trial) and nose test suites out of the box;

These may be helpful as well...

https://stackoverflow.com/a/21615720/9530790

https://stackoverflow.com/a/23617918/9530790