I want to test the exception part of my code.
def main():
try:
logger.info("Ejecución planificada proceso Mae_CIL")
a = ObjectA()
a.method()
logger.info("Success")
except Exception as e:
logger.error("Error: %s" % e)
@mock.patch.object(ObjectA, 'method')
def test_main(self, mock_method):
# Case 1: Success
mock_method.return_value = None
main()
self.assertEqual(1, 1)
# Case 2: Test Exception
mock_method.return_value = Exception
self.assertRaises(Exception, main)
The Case 1 test the main method. And the Case 2 test the exception but the test fail with this message 'Exception: Exception not raised by main'
How can i test the exception part??