Anonymous Anonymous - 7 months ago 18
Python Question

Python - test that succeeds when exception is not raised

I know about

unittest
Python module.

I know about
assertRaises()
method of
TestCase
class.

I would like to write a test that succeeds when an exception is not raised.

Any hints please?

Answer

The test runner will catch all exceptions you didn't assert would be raised. Thus:

doStuff()
self.assert_(True)

This should work fine. You can leave out the self.assert_ call, since it doesn't really do anything. I like to put it there to document that I didn't forget an assertion.

Comments