unittest assertRaises Problem

attn.steven.kuo at gmail.com attn.steven.kuo at gmail.com
Mon Apr 16 18:33:33 EDT 2007


On Apr 16, 3:13 pm, "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 second argument should be a callable object, not the
result from invoking that callable object.  Thus, change

self.assertRaises(ValueError, f.testException())

to

self.assertRaises(ValueError, f.testException)

--
Hope this helps,
Steven




More information about the Python-list mailing list