pytest
pytest copied to clipboard
Full diff thinks unittest.mock.ANY fails equality check in assertions
When unittest.mock.ANY is used, and assertion fails, the pytest diff is confusing, and it mistakenly marks ANY being non-equal to the value on the other side. This is especially confusing with lists comparison. Simple example:
from unittest.mock import ANY
assert [{'id': 1, 'val': 5}] == [{'id': ANY, 'val': 4}]
The full diff produced with pytest -vv:
E AssertionError: assert [{'id': 1, 'val': 5}] == [{'id': <ANY>, 'val': 4}]
E At index 0 diff: {'id': 1, 'val': 5} != {'id': <ANY>, 'val': 4}
E Full diff:
E - [{'id': 1, 'val': 5}]
E ? ^ ^
E + [{'id': <ANY>, 'val': 4}]
E ? ^^^^^ ^
In the full diff you can see that not only val, but also id is marked as being different, which is confusing, as it does not trigger the assertion. It would be a lot more clear if full diff only show the values actually comparing non-equal
pytest version: 3.6.2