Created
January 7, 2015 22:59
-
-
Save boris-42/bd81f44287a3e8c4a402 to your computer and use it in GitHub Desktop.
Python mocking 2 or more open() calls in method
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 | |
| @mock.patch("<path_to_module_with_function>.open", create=True) | |
| def test_some_your_method(self, mock_open): | |
| mock.open.side_effect = [ | |
| mock.mock_open(read_data="Data from file 1").return_value, | |
| mock.mock_open(read_data="Data from file 2").return_value | |
| ] | |
| # calling your_method() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment