Skip to content

Instantly share code, notes, and snippets.



Last active Mar 15, 2017
What would you like to do?
Demonstrates the dangers and scope of this kind of mocking.
import unittest
import mock
import users
import file_utils
class UsersTest(unittest.TestCase):
_file_path = "INSERT_PATH_HERE"
def test_get_users(self):
user = "user1"
# create a mock for read_file which returns the value user
file_utils.read_file = mock.MagicMock(name="read_file", return_value=user)
result = users.get_users()
self.assertEqual(user, result)
def test_get_users_whoops(self):
print file_utils.read_file
if __name__ == '__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.