Skip to content

Instantly share code, notes, and snippets.

@LiamJolly
Last active March 15, 2017 08:56
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/ffdb88c32c1342a4f4be219b8cc16886 to your computer and use it in GitHub Desktop.
Save LiamJolly/ffdb88c32c1342a4f4be219b8cc16886 to your computer and use it in GitHub Desktop.
Testing using mock deocorators.
import unittest
import mock
import users
import file_utils
class UsersTest(unittest.TestCase):
_file_path = "INSERT_PATH_HERE"
@mock.patch("file_utils.read_file", return_value="user1")
def test_get_users(self, mock_read):
result = users.get_users()
self.assertEqual("user1", result)
mock_read.assert_called_once_with(self._file_path)
def test_get_users_whoops(self):
print file_utils.read_file
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment