Skip to content

assertion introspection is missing when pytest produces a diff #13198

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

Open
KotlinIsland opened this issue Feb 6, 2025 · 2 comments
Open

assertion introspection is missing when pytest produces a diff #13198

KotlinIsland opened this issue Feb 6, 2025 · 2 comments
Labels
topic: rewrite related to the assertion rewrite mechanism type: enhancement new feature or API change, should be merged into features branch

Comments

@KotlinIsland
Copy link

KotlinIsland commented Feb 6, 2025

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?

@The-Compiler
Copy link
Member

Not sure I follow, are you referring to the + where [1, 2, 2] = get_data(2) missing in the first case?

@KotlinIsland
Copy link
Author

yes, exactly. "assertion introspection" was the name for this feature that I could find in the docs

@Zac-HD Zac-HD changed the title (🐞) assertion introspection is missing when pytest produces a diff assertion introspection is missing when pytest produces a diff Mar 9, 2025
@Zac-HD Zac-HD added type: enhancement new feature or API change, should be merged into features branch topic: rewrite related to the assertion rewrite mechanism labels Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: rewrite related to the assertion rewrite mechanism type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

3 participants