How does one write a unittest that fails only if a function doesn't throw an expected exception?
Use TestCase.assertRaises (or TestCase.failUnlessRaises) from the unittest module, for example:
TestCase.assertRaises
TestCase.failUnlessRaises
import mymod class MyTestCase(unittest.TestCase): def test1(self): self.assertRaises(SomeCoolException, mymod.myfunc)
2.1m questions
2.1m answers
60 comments
57.0k users