mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
docs: Add references to AsyncMock in unittest.mock.patch (#13681)
Update the docs as patch can now return an AsyncMock if the patched object is an async function.
This commit is contained in:
parent
fa3a38d81f
commit
f5e7f39d29
2 changed files with 21 additions and 8 deletions
|
@ -1631,8 +1631,9 @@ def patch(
|
|||
is patched with a `new` object. When the function/with statement exits
|
||||
the patch is undone.
|
||||
|
||||
If `new` is omitted, then the target is replaced with a
|
||||
`MagicMock`. If `patch` is used as a decorator and `new` is
|
||||
If `new` is omitted, then the target is replaced with an
|
||||
`AsyncMock if the patched object is an async function or a
|
||||
`MagicMock` otherwise. If `patch` is used as a decorator and `new` is
|
||||
omitted, the created mock is passed in as an extra argument to the
|
||||
decorated function. If `patch` is used as a context manager the created
|
||||
mock is returned by the context manager.
|
||||
|
@ -1650,8 +1651,8 @@ def patch(
|
|||
patch to pass in the object being mocked as the spec/spec_set object.
|
||||
|
||||
`new_callable` allows you to specify a different class, or callable object,
|
||||
that will be called to create the `new` object. By default `MagicMock` is
|
||||
used.
|
||||
that will be called to create the `new` object. By default `AsyncMock` is
|
||||
used for async functions and `MagicMock` for the rest.
|
||||
|
||||
A more powerful form of `spec` is `autospec`. If you set `autospec=True`
|
||||
then the mock will be created with a spec from the object being replaced.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue