The py.test assert docs say
... if you specify a message with the assertion like this:
assert a % 2 == 0, "value was odd, should be even"
then no assertion introspection takes places at all and the message will be simply shown in the traceback.
Python's builtin unittest
module does this too, unless your TestCase
sets longMessage = True
.
Having the nice assert formatting is test developer friendly, while the custom message is more business-requirement / human friendly. The custom message is especially helpful when you're not in the context of the test, i.e. it answers what that assert is doing there, without having to look at the code. So, I'd like to have both messages.
Is there any way to get py.test's nice assert introspection and formatting AND print a custom message?