Skip to content

Help with plugin assertion rewriting #5931

@JBKahn

Description

@JBKahn

Hey, I was looking at the pytest-clarity package and it does something really nice, imo, which is it turns this:

pytest

into:

pytest

The downside is that the rewriting results in a loss of functionality:

a = [1, 2, 3]
b = [1, 2]

def test_a():
    assert len(a) == len(b)

Goes from

    def test_a():
>       assert len(a) == len(b)
E       assert 3 == 2
E        +  where 3 = len([1, 2, 3])
E        +  and   2 = len([1, 2])

to

    def test_a():
>       assert len(a) == len(b)
E       assert left == right failed.
E         Showing split diff:
E
E         left:  3
E         right: 2

I've been digging through the source and I can't quite find the right part to use to do this. It stems from use of pytest_assertrepr_compare but I can't find anything in pytest I can use to construct that 3 = len([1, 2, 3]). I'm looking for some pointers if anyone can help put me on the right track. I was barking down the AssertionRewriter which I think is what I'm looking for but I can't quite put my finger on how to modify these assertions in way that still utilizes that code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions