Created
January 22, 2015 06:04
-
-
Save curzona/96bac22da2de3191c2d8 to your computer and use it in GitHub Desktop.
unittest with mock __builtin__.open
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 mock | |
| import unittest | |
| class TestOpen(unittest.TestCase): | |
| def test_mock_open(self): | |
| m = mock.patch('__builtin__.open', | |
| mock.mock_open(read_data="some text")) | |
| m.start() | |
| with open('somefile.txt', 'rb') as fin: | |
| text = fin.read() | |
| assert text == "some text" | |
| m.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment