Hi,

Despite being touted as one of its strengths, I think the output on
comparison of complex objects could use some work. I work with many
tests that compare dictionaries for example ('assert result ==
expected'), and if they fail I usually have to dig around, manually
iterate through them etc to figure out where the difference is.

Here is an example.

tests/unit/formatters/test_WxPhrase.py:638: in
test_mergeBackSeparableAttributesMultipleSentencesOK
>       assert result == expected
E       assert {frozenset(['...00:00 GMT))]]} == {frozenset(['T...00:00 GMT))]]}
E         Skipping 161 identical leading characters in diff
E           00 GMT))]]}

Note using --tb=long does not expand the diff text -- it just expands
the traceback stack which is not helpful in this case.

If I use the compare() method in testfixtures library instead of a
plain assert statement, the output is a bit better:

tests/unit/formatters/test_WxPhrase.py:639: in
test_mergeBackSeparableAttributesMultipleSentencesOK
>       compare(result, expected)
../GFESuite-Builds/Release/release/lib/python2.7/site-packages/testfixtures/comparison.py:268:
in compare
>       raise AssertionError(message)
E       AssertionError: dict not as expected:
E
E       values differ:
E       frozenset(['TS']): [[WxStatBlock((Jan 01 70 16:00:00 GMT, Jan
01 70 22:00:00 GMT))],
E        [WxStatBlock((Jan 01 70 10:00:00 GMT, Jan 01 70 16:00:00
GMT))]] != [[WxStatBlock((Jan 01 70 16:00:00 GMT, Jan 01 70 22:00:00
GMT))],
E        [WxStatBlock((Jan 01 70 10:00:00 GMT, Jan 01 70 16:00:00 GMT))]]

OK - now I can see that the assert is failing because the order is different.

Is there a way, or could one be added, to be more verbose in object
(esp. list/set/dict) comparison? An option like --cmp=verbose (or
maybe it makes sense incorporated into --tb=long??)

I had a half-hearted attempt at writing my own
pytest_assertrepr_compare to use this compare() method (I really like
using natural assert statements) but py.test didn't seem to pick it
up. I might investigate this further but also maybe this is a good
area for pytest to improve?

thanks,
Brianna

-- 
They've just been waiting in a mountain for the right moment:
http://modernthings.org/
_______________________________________________
Pytest-dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to