Generally in unit test, we match the responses with an expected value . But there are cases , where calling a method or passing an incorrect value (or type of value) may raise an exception . This exception might me a custom exception . Or the message or error code might me specific to the situation. So how to write test for the same.
1. Calling a method with incorrect type , raises an exception.
class MyTest(unittest.TestCase): def test_exception(self): with self.assertRaises(xmlrpclib.Fault) as cm: self.Proxy.setParameter('name', 1234) self.fail('Expected exception of type xmlrpc.Fault')