[TIP] unittest2 assertRaises failure message

Michael Rene Armida me at marmida.com
Tue Jan 15 12:14:17 PST 2013


On Tue, Jan 15, 2013 at 11:41 AM, Olemis Lang <olemis at gmail.com> wrote:

> No that's not the case as I want to detect whether expected exception
> was not raised or any other kind of failure .
>
>
I don't understand why it's insufficient.  Here's your problem, as I
understand it:

1) you want to check for the type and existence of an exception
2) you want to guarantee that the raised exception has some specific
information, beyond just its type

#1 above is already handled by unittest2.assertRaises.  #2 is easily
attained, if I understand correctly that you're looking for the value of
'x' in the case the exception is raised.  You could do at least these two
things to examine the value of 'x':

1) assert the contents of the exception's message
2) give the exception object an attribute for the relevant value, which you
will assert

In either case, you will end up with a descriptive assertion failure
message showing what went wrong.

I have created an example here: https://gist.github.com/4541594

It's possible that I'm just misunderstanding your problem, and if so, I'm
sorry.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20130115/78e8f651/attachment.htm>


More information about the testing-in-python mailing list