This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author butla
Recipients butla, docs@python
Date 2016-11-18.13:17:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Documentation of mock_open doesn't say how to use it in real-life test situations (when you're probably not mocking in __main__). I've spent some time scratching my head and googling for the way to mock-out the "open" function, want to spare other people the hassle.

The thing is that "open" needs to be mocked out from the magical "builtins" module, and not from the place of usage (like when mocking everything that's not built-in). So it's not obvious how to do that, especially that the example with __main__ makes it look like the normal mocking approach should work.

I still don't fully understand why mocking "" can work from interpreter, but that's a different thing...
Date User Action Args
2016-11-18 13:17:52butlasetrecipients: + butla, docs@python
2016-11-18 13:17:52butlasetmessageid: <>
2016-11-18 13:17:52butlalinkissue28733 messages
2016-11-18 13:17:52butlacreate