mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Closes issue 17467. Add readline and readlines support to unittest.mock.mock_open
This commit is contained in:
parent
94f2788a85
commit
04cbe0c35b
4 changed files with 141 additions and 8 deletions
|
@ -1989,8 +1989,12 @@ mock_open
|
|||
default) then a `MagicMock` will be created for you, with the API limited
|
||||
to methods or attributes available on standard file handles.
|
||||
|
||||
`read_data` is a string for the `read` method of the file handle to return.
|
||||
This is an empty string by default.
|
||||
`read_data` is a string for the `read`, `readline`, and `readlines` methods
|
||||
of the file handle to return. Calls to those methods will take data from
|
||||
`read_data` until it is depleted. The mock of these methods is pretty
|
||||
simplistic. If you need more control over the data that you are feeding to
|
||||
the tested code you will need to customize this mock for yourself.
|
||||
`read_data` is an empty string by default.
|
||||
|
||||
Using `open` as a context manager is a great way to ensure your file handles
|
||||
are closed properly and is becoming common::
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue