Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The unit test for our simple exception_example, uses side_effect to trigger the exception.
import exception_example
import unittest
import mock
class ExceptionExampleTest(unittest.TestCase):
def test_does_user_exist(self):
self.assertTrue(exception_example.does_user_exist("user1"))
def test_does_user_exist_no_user(self):
with mock.patch("exception_example.find_user", autospec=True, side_effect=Exception):
self.assertFalse(exception_example.does_user_exist("user2"))
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.