-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
This is on pytest 3.4.2, I don't think other environmental parameters are relevant.
I've noticed a few times that I'm struggling with the +/- usage of long string diffs (-v) as that I never can immediately understand what was expected and what was found.
First, pytest documentation shows the same style of writing assertions as I do, in the form of:
assert my_result == 'bob'
So the left hand would hold the value the UUT gave me and the right hand is what the test is expecting it to be. If you use this for long strings and -v for showing diffs this ends up in the following:
assert app.mailer_mock.messages[0][2] == """\
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Subject: Re: Hilfe
To: [email protected]
From: [email protected]
In-Reply-To: 12345
Message-ID: <[email protected]>
Dear Customer,
we could not find a valid SLA for you. If you are sure to have one,
please check if you provided the correct PIN.
Best regards,
the Flying Circus support team
"""Output:
AssertionError: assert 'Content-Type...upport team\n' == 'Content-Type:...upport team\n'
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Subject: Re: Hilfe
To: [email protected]
+ From: [email protected]
In-Reply-To: 12345
Message-ID: <[email protected]>
- From: [email protected]
Dear Customer,
we could not find a valid SLA for you. If you are sure to have one,
please check if you provided the correct PIN.
Best regards,
the Flying Circus support teamWhen looking at that output, I would like to interpret it as "the + shows me what the test found that was there but not expected" and "the - shows me what the test expected but is missing".
Obviously this comes down to the +/- being a convention that implies that the left hand side shows the expected value and the right hand side the result of the UUT. However, writing it down the other way makes the test IMHO less readable and is also known as "yoda expressions" and usually frowned upon [citation needed].
This issue is probably more about discussion and understanding intent and stance from pytest's perspective and likely won't change the way its reported. Although I could also imagine adding a configuration knob for this behaviour.