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 <1479475072.8.0.338397997846.issue28733@psf.upfronthosting.co.za>
In-reply-to
Content
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 "__main__.open" can work from interpreter, but that's a different thing...
History
Date User Action Args
2016-11-18 13:17:52butlasetrecipients: + butla, docs@python
2016-11-18 13:17:52butlasetmessageid: <1479475072.8.0.338397997846.issue28733@psf.upfronthosting.co.za>
2016-11-18 13:17:52butlalinkissue28733 messages
2016-11-18 13:17:52butlacreate