[TIP] unittest2 assertRaises failure message
Olemis Lang
olemis at gmail.com
Tue Jan 15 11:41:46 PST 2013
On 1/15/13, Michael Rene Armida <me at marmida.com> wrote:
> I'd suggest inspecting the context manager object, which exposes the caught
> exception as an attribute. You can see it here in the unittest2 docs:
> http://www.voidspace.org.uk/python/articles/unittest2.shtml#assertraises
>
No that's not the case as I want to detect whether expected exception
was not raised or any other kind of failure .
> In your case, you'd want something like:
>
> with self.assertRaises(MyException) as cm:
> # Assertions et al.
> self.assertEqual(cm.exception.somevalue, 42)
>
Therefore it is a bit more heavy metal than this ;)
>
> As for dumping the globals and locals during a failure, I don't know how to
> hook that into the unittest2 machinery.
Already implemented in the patch I mentioned before
;)
> However, nosetests does allow you
> to invoke pdb on failures with a command-line switch,
I've never been a nose user ...
:'(
> whic allows you to
> interactively poke around at the locals, globals, and whatever else you
> might want. pdb has a learning curve, but I think the payoff makes it
> worthwhile.
>
... but this seems interesting .
Thanks for your reply .
--
Regards,
Olemis.
Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/
Featured article:
More information about the testing-in-python
mailing list