pytest
pytest copied to clipboard
`AssertionError`s with differing items in dict of lists do not display properly when not running in verbose mode
- [X] a detailed description of the bug or problem you are having
when an
assert
statement fails where the values being compared aredict
s oflist
s with 8 or more items in the list, it does not show what part of the list was different in the output. - [ ] output of
pip list
from the virtual environment you are using not using pip - [X] pytest and operating system versions py pytest 8.0, windows 10/11
- [X] minimal example if possible
def test_something():
value1 = {"asdf": [1, 1, 1, 1, 1, 1, 1, 1]}
value2 = {"asdf": [1, 1, 1, 1, 1, 1, 1, 2]}
assert value1 == value2
AssertionError: assert {'asdf': [1, ...1, 1, 1, ...]} == {'asdf': [1, ...1, 1, 1, ...]}
Differing items:
{'asdf': [1, 1, 1, 1, 1, 1, ...]} != {'asdf': [1, 1, 1, 1, 1, 1, ...]}
Use -v to get more diff
the truncated diff does not show what part was different. it should instead display something like:
Differing items:
{'asdf': [1, 1, 1, ...1, 1]} != {'asdf': [1, 1, 1, ...1, 2]}
Hi, planning to work on this soon!
Would it make sense to update the existing message-style of sequences, or is the original example preferred? I'm imagining the following
Differing items:
{'asdf': At index 0 diff: 1 != 2}
Differing items:
{'asdf': Right contains 2 more items, first extra item: 3}
i'm not sure what the best way to do it is. providing a good message for assertion errors that account for possible data structure seems like an impossible task. though i'm probably leaning towards the existing style as it gives more info/context