I've copied and pasted the following code directly from the Python mock docs:
from unittest.mock import patch, mock_open
with patch('__main__.open', mock_open(read_data='bibble')) as m:
with open('foo') as h:
result = h.read()
m.assert_called_once_with('foo')
assert result == 'bibble'
When I run this I get the following error:
AttributeError: <module '__main__' from 'path/to/file'> does not have the attribute 'open'
Given that this is the example given in the documentation, I'm not sure where else to turn. I'm running Python 3.4.5.