import unittest from unittest.mock import patch, Mock class UnderTest(): def __init__(self, param): if isinstance(param, int): raise ProductionError(f'param {param} should be an integer', 'message2') class ProductionError (Exception): def __init__(message1, message2): # do something in production code pass class MockError (ProductionError): def __init__(*args): # it seems as no argument is passed here print(args[1], args[0]) class Test (unittest.TestCase): def setUp(self): patcher = patch('__main__.ProductionError', instance=True, side_effect=MockError) self.mockerror = patcher.start() self.addCleanup(patcher.stop) def test_undertest(self): object = UnderTest(1) if __name__ == '__main__': unittest.main()