Skip to content

Instantly share code, notes, and snippets.

@boris-42
Created January 7, 2015 22:59
Show Gist options
  • Select an option

  • Save boris-42/bd81f44287a3e8c4a402 to your computer and use it in GitHub Desktop.

Select an option

Save boris-42/bd81f44287a3e8c4a402 to your computer and use it in GitHub Desktop.
Python mocking 2 or more open() calls in method
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