Skip to content

Instantly share code, notes, and snippets.

@Avantol13
Created November 30, 2018 22:24
Show Gist options
  • Save Avantol13/fc9ece991e3aa2bbaad1f2f2e95699fb to your computer and use it in GitHub Desktop.
Save Avantol13/fc9ece991e3aa2bbaad1f2f2e95699fb to your computer and use it in GitHub Desktop.
# Python 2
from mock import patch, mock_open
creds_file = "This text is not really in a file."
mocked_open = patch("__builtin__.open", mock_open(read_data=creds_file))
mocked_open.start()
with open("any_file_name") as mocked_file:
print(mocked_file.read())
mocked_open.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment