Mock Exception With Side Effect Raised In Class Method And Caught In Calling Method Gives 'did Not Raise'
Using side_effect, I am trying to raise an exception when a mock is called but I get a DID NOT RAISE EXCEPTION error that I do not understand. Based largely on this answer, I have
Solution 1:
Pytest cannot detect an exception because in get_response_from_external_api
you are catching all of them. Depending on your requirements, you have these options:
- Don't catch the exceptions in
get_response_from_external_api
. - Catch the exceptions, do whatever you want and then re-raise them.
- Instead of detecting an exception with
pytest.raises
, use capsys fixture to capture what is being printed and make assertions on that output.
Post a Comment for "Mock Exception With Side Effect Raised In Class Method And Caught In Calling Method Gives 'did Not Raise'"