Last active
April 2, 2017 08:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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