[docs] The examples in http://docs.python.org/3.3/library/unittest.mock-examples.html for mock builtin functions (such as 'open') does not work.

张小潘 zhangxiaopan at gmail.com
Wed Feb 27 20:31:57 CET 2013


Hi there,

http://docs.python.org/3.3/library/unittest.mock-examples.html
gives the following example for using unittest.mock module to mock builtin
functions:

>>> mock = MagicMock(return_value = sentinel.file_handle)>>> with patch('__builtin__.open', mock):...     handle = open('filename', 'r')...>>> mock.assert_called_with('filename', 'r')>>> assert handle == sentinel.file_handle, "incorrect file handle returned"


By running this example with Python3.3, I received the following error:

ImportError: No module named '__builtin__'

Changing the module name to '__builtins__' does NOT work either.

Changing the module name to 'builtins' DOES work.

Could we fix the document? and could somebody here to explain the
difference between these names for builtins module?

Thanks.

-- 
张小潘
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20130227/46636ef0/attachment-0001.html>


More information about the docs mailing list