Skip to content

Option to show full assertion diff #381

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

Closed
pytestbot opened this issue Nov 7, 2013 · 1 comment
Closed

Option to show full assertion diff #381

pytestbot opened this issue Nov 7, 2013 · 1 comment
Labels
type: enhancement new feature or API change, should be merged into features branch

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Wolfgang Schnerring (BitBucket: wosc, GitHub: wosc)


If you compare e.g. a larger dict and the assertion fails, the output is truncated with ellipses in it -- which sometimes hide exactly the parts that differ ("{'foo': 'bar', ... } != {'foo': 'bar', ...}"). Even passing -v doesn't help.

I've looked at _pytest.util._compare_eq_dict, it uses py.io.saferepr, which in turn has a maxlength parameter, but pytest does not use that -- I guess it should.


@pytestbot
Copy link
Contributor Author

Original comment by Floris Bruynooghe (BitBucket: flub, GitHub: flub):


Hi, I believe this is already fixed. Currently you get this:

cd; py.test /tmp/sandbox/test_foo.py
============================================= test session starts ==============================================
platform linux2 -- Python 2.7.4 -- pytest-2.4.3.dev2
collected 1 items 

../../tmp/sandbox/test_foo.py F

=================================================== FAILURES ===================================================
__________________________________________________ test_dict ___________________________________________________

    def test_dict():
        a = {'aaaaaa': 'bbbbbb',
             'cccccc': 'dddddd',
             'eeeeee': 'ffffff',
             'gggggg': 'hhhhhh',
             'iiiiii': 'jjjjjj'}
        b = {'aaaaaa': 'bbbbbb',
             'cccccc': 'dddddd',
             'eeeeee': 'ffffff',
             'gggggg': 'hhhhhh',
             'iiiiii': 'kkkkkk'}
>       assert a == b
E       assert {'aaaaaa': 'b...'hhhhhh', ...} == {'aaaaaa': 'bb...'hhhhhh', ...}
E         Omitting 4 identical items, use -v to show
E         Differing items:
E         {'iiiiii': 'jjjjjj'} != {'iiiiii': 'kkkkkk'}

/tmp/sandbox/test_foo.py:12: AssertionError
=========================================== 1 failed in 0.01 seconds ===========================================

And with -v:

cd; py.test /tmp/sandbox/test_foo.py -v
============================================= test session starts ==============================================
platform linux2 -- Python 2.7.4 -- pytest-2.4.3.dev2 -- /home/flub/.virtualenvs/pytest/bin/python
collected 1 items 

../../tmp/sandbox/test_foo.py:1: test_dict FAILED

=================================================== FAILURES ===================================================
__________________________________________________ test_dict ___________________________________________________

    def test_dict():
        a = {'aaaaaa': 'bbbbbb',
             'cccccc': 'dddddd',
             'eeeeee': 'ffffff',
             'gggggg': 'hhhhhh',
             'iiiiii': 'jjjjjj'}
        b = {'aaaaaa': 'bbbbbb',
             'cccccc': 'dddddd',
             'eeeeee': 'ffffff',
             'gggggg': 'hhhhhh',
             'iiiiii': 'kkkkkk'}
>       assert a == b
E       assert {'aaaaaa': 'b...'hhhhhh', ...} == {'aaaaaa': 'bb...'hhhhhh', ...}
E         Common items:
E         {'aaaaaa': 'bbbbbb',
E          'cccccc': 'dddddd',
E          'eeeeee': 'ffffff',
E          'gggggg': 'hhhhhh'}
E         Differing items:
E         {'iiiiii': 'jjjjjj'} != {'iiiiii': 'kkkkkk'}

/tmp/sandbox/test_foo.py:12: AssertionError
=========================================== 1 failed in 0.01 seconds ==========================================

Certainly this second option shows you all items in the dictionary, although I'll admit not as a straight diff.

Feel free to re-open if you disagree or I misunderstood this.

@pytestbot pytestbot added the type: enhancement new feature or API change, should be merged into features branch label Jun 15, 2015
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

No branches or pull requests

1 participant