pytest icon indicating copy to clipboard operation
pytest copied to clipboard

`AssertionError`s with differing items in dict of lists do not display properly when not running in verbose mode

Open DetachHead opened this issue 1 year ago • 3 comments

  • [X] a detailed description of the bug or problem you are having when an assert statement fails where the values being compared are dicts of lists 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]}

DetachHead avatar Feb 15 '24 06:02 DetachHead

Hi, planning to work on this soon!

mberkowitz03 avatar Mar 31 '24 15:03 mberkowitz03

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}

reaganjlee avatar Aug 10 '24 06:08 reaganjlee

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

DetachHead avatar Aug 11 '24 09:08 DetachHead