[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.
berker.peksag at gmail.com
Mon Mar 25 07:14:22 CET 2013
On Wed, Feb 27, 2013 at 9:31 PM, 张小潘 <zhangxiaopan at gmail.com> wrote:
> Hi there,
> gives the following example for using unittest.mock module to mock builtin
>>>> 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 for your report. I've opened http://bugs.python.org/issue17539 to fix it.
More information about the docs