Skip to content
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

AssertionErrors with differing items in dict of lists do not display properly when not running in verbose mode #11980

Open
3 of 4 tasks
DetachHead opened this issue Feb 15, 2024 · 3 comments · May be fixed by #12717
Open
3 of 4 tasks
Labels
topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch

Comments

@DetachHead
Copy link
Contributor

DetachHead commented Feb 15, 2024

  • 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
  • pytest and operating system versions py
    pytest 8.0, windows 10/11
  • 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]}
@bluetech bluetech added type: enhancement new feature or API change, should be merged into features branch topic: reporting related to terminal output and user-facing messages and errors labels Feb 17, 2024
@mberkowitz03
Copy link

Hi, planning to work on this soon!

@reaganjlee
Copy link
Contributor

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}

@DetachHead
Copy link
Contributor Author

DetachHead commented Aug 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants