I think setting a patch mock's side_effect to raise an exception is a valid use case.
In this example, we're simulating a blockchain error in an API that we're coding, and testing that instead of a 500 Internal Server Error, our API returns a 400 with a nice error message: with mock.patch('yourapi.w3.eth') as thing: eth.sendRawTransaction.side_effect = lambda: raise SomeException('some message') result = testclient.post('/yourapi') assert result.status_code == 400 assert result.message = 'some message'
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ZLDSRQQE25OGE45WYGIVEE4PCXUBWUXP/ Code of Conduct: http://python.org/psf/codeofconduct/