pytest icon indicating copy to clipboard operation
pytest copied to clipboard

assertion introspection is missing when pytest produces a diff

Open KotlinIsland opened this issue 10 months ago • 2 comments

def get_data(last):
    return [1, 2, last]

def test_list_compare():
    assert [1, 2, 3] == get_data(2)

def test_int_compare():
    assert 1 == get_data(2)
> uv run pytest tests
...
======================== FAILURES ==============================================
____________________________ test_list_compare __________________________________

    def test_list_compare():
>       assert [1, 2, 3] == get_data(2)
E       assert [1, 2, 3] == [1, 2, 2]
E         
E         At index 2 diff: 3 != 2
E         
E         Full diff:
E           [
E               1,
E               2,
E         -     2,
E         ?     ^
E         +     3,
E         ?     ^
E           ]

tests\test_it.py:5: AssertionError
______________________________ test_int_compare _______________________________

    def test_int_compare():
>       assert 1 == get_data(2)
E       assert 1 == [1, 2, 2]
E        +  where [1, 2, 2] = get_data(2)

tests\test_it.py:8: AssertionError

while this minification doesn't represent an actual use-case, only the issue in question, there are many cases where the diff of the lists is not as useful to me as the breakdown of how it came to be, could there be a verbosity option to display both the diff, and the breakdown?

KotlinIsland avatar Feb 06 '25 01:02 KotlinIsland