How to mock a exception class??
wencan opened this issue · 1 comments
wencan commented
I need mock a exception class, and raise it.
my code:
class TestService(unittest.TestCase):
def test_raise(self):
class MyException(BaseException):
pass
mockedException = mock.create_autospec(spec=MyException, instance=True)
self.assertIsInstance(mockedException, BaseException)
raise mockedException
output:
TypeError: exceptions must derive from BaseException
cjw296 commented
This is not the right place to ask, please try the testing-in-python mailing list, and read the documentation for mock on python.org.