Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Doc/library/unittest.mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,16 @@ And for reading files::
>>> m.assert_called_once_with('foo')
>>> assert result == 'bibble'

If you want to mock open for use in another module you can mock
builtins.open:

>>> with patch('builtins.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'


.. _auto-speccing:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add in example to unittest.mock.rst showing how to mock builtins.open in
cases where builtins.open is mocked in another module.