Created
January 30, 2016 09:27
-
-
Save itsmemattchung/cda794287f2f0f48eca8 to your computer and use it in GitHub Desktop.
Example on mocking a tempfile
This file contains hidden or 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 tempfile | |
import mock | |
def use_tempfile(): | |
dest_dir = '/tmp' | |
with tempfile.NamedTemporaryFile(dir=dest_dir, delete=False) as temp_dest: | |
print "hello world" | |
return temp_dest | |
@mock.patch.object(tempfile, 'NamedTemporaryFile') | |
def call_use_tempfile(temp_file): | |
return use_tempfile() | |
if __name__ == "__main__": | |
print call_use_tempfile() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment