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

Help with plugin assertion rewriting #5931

Closed
JBKahn opened this issue Oct 8, 2019 · 3 comments
Closed

Help with plugin assertion rewriting #5931

JBKahn opened this issue Oct 8, 2019 · 3 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors type: question general question, might be closed after 2 weeks of inactivity

Comments

@JBKahn
Copy link

JBKahn commented Oct 8, 2019

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.

@blueyed
Copy link
Contributor

blueyed commented Oct 9, 2019

Might be good to get feedback in #5933 how the new method / alternatives would be useful for the plugin, since the plugin would benefit here from having the original explanation (or a way to say where it should be inserted (via special placeholder)).

@JBKahn
Copy link
Author

JBKahn commented Oct 9, 2019

I'll take a look tomorrow myself

@JBKahn
Copy link
Author

JBKahn commented Oct 9, 2019

Thanks for getting back so quickly!

@Zac-HD Zac-HD added topic: reporting related to terminal output and user-facing messages and errors type: question general question, might be closed after 2 weeks of inactivity labels Oct 11, 2019
@Zac-HD Zac-HD closed this as completed Oct 29, 2019
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: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants