unittest assertRaises Problem

john puopolo at gmail.com
Tue Apr 17 02:59:22 CEST 2007


On Apr 16, 6:35 pm, Jean-Paul Calderone <exar... at divmod.com> wrote:
> On 16 Apr 2007 15:13:42 -0700, john <puop... at gmail.com> wrote:
>
>
>
> >All:
>
> >Hi. I am an experienced developer (15 yrs), but new to Python and have
> >a question re unittest and assertRaises. No matter what I raise,
> >assertRaises is never successful. Here is the test code:
>
> >class Foo:
> >    def testException(self):
> >       raise ValueError
>
> >class FooTestCase(unittest.TestCase):
>
> >       testTryThis(self):
> >          f = Foo()
> >          self.assertRaises(ValueError, f.testException())
>
> The 2nd argument to assertRaises should be a callable.  assertRaises
> will call it (so that it can do exception handling), so you shouldn't:
>
>     self.assertRaises(ValueError, f.testException)
>
> Jean-Paul

Steven, Jean-Paul:

Thank you both for your answers - worked like a charm!

Best,
John




More information about the Python-list mailing list