Skip to content

assertion introspection is missing when pytest produces a diff #13198

Open
@KotlinIsland

Description

@KotlinIsland
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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions