Skip to content

Instantly share code, notes, and snippets.

@LiamJolly
Last active April 2, 2017 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LiamJolly/ac9d919ba8516263bbcb40ec44b8f8b1 to your computer and use it in GitHub Desktop.
Save LiamJolly/ac9d919ba8516263bbcb40ec44b8f8b1 to your computer and use it in GitHub Desktop.
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