I&#39;d suggest inspecting the context manager object, which exposes the caught exception as an attribute.  You can see it here in the unittest2 docs:<div><a href="http://www.voidspace.org.uk/python/articles/unittest2.shtml#assertraises">http://www.voidspace.org.uk/python/articles/unittest2.shtml#assertraises</a></div>
<div><br></div><div>In your case, you&#39;d want something like:</div><div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">with self.assertRaises(MyException) as cm:</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">    # Assertions et al.</span></div><div><font color="#222222" face="arial, sans-serif">self.assertEqual(cm.exception.somevalue, 42)</font></div>
<div><br></div><div><br></div><div><font color="#222222" face="arial, sans-serif">As for dumping the globals and locals during a failure, I don&#39;t know how to hook that into the unittest2 machinery.  However, nosetests does allow you to invoke pdb on failures with a command-line switch, 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.</font></div>
<div><br><div class="gmail_quote">On Sun, Jan 13, 2013 at 7:40 PM, Olemis Lang <span dir="ltr">&lt;<a href="mailto:olemis@gmail.com" target="_blank">olemis@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all !<br>
:)<br>
<br>
The body of a `unittest2` test case looks like this ...<br>
<br>
{{{<br>
#!python<br>
<br>
# ------8&lt;--- Further code omitted ---8&lt;------<br>
    for x in seq:<br>
        # ------8&lt;--- Further code omitted ---8&lt;------<br>
        with self.assertRaises(MyException) as cm:<br>
            # Assertions et al.<br>
<br>
}}}<br>
<br>
As you can see there&#39;s a chance for assertRaises to fail and as a<br>
consequence a message like «AssertionError: MyException not raised» is<br>
included in ouput . That&#39;s not informative enough *in this case* since<br>
I&#39;d like to know e.g. the exact value of x .<br>
<br>
Q:<br>
  - Is there a chance to customize `assertRaises` failure message ?<br>
  - Is there any chance for e.g. dumping `locals()` ?<br>
  - Can `unittest2` be helpful somehow ?<br>
  - Any other suggestions ?<br>
<br>
Any feedback will be welcome . Thanks in advance .<br>
<br>
<br>
--<br>
Regards,<br>
<br>
Olemis.<br>
<br>
Blog ES: <a href="http://simelo-es.blogspot.com/" target="_blank">http://simelo-es.blogspot.com/</a><br>
Blog EN: <a href="http://simelo-en.blogspot.com/" target="_blank">http://simelo-en.blogspot.com/</a><br>
<br>
Featured article:<br>
<br>
_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
</blockquote></div><br></div>