@@ -1321,8 +1321,10 @@ patch
13211321 is patched with a *new * object. When the function/with statement exits
13221322 the patch is undone.
13231323
1324- If *new * is omitted, then the target is replaced with a
1325- :class: `MagicMock `. If :func: `patch ` is used as a decorator and *new * is
1324+ If *new * is omitted, then the target is replaced with an
1325+ :class: `AsyncMock ` if the patched object is an async function or
1326+ a :class: `MagicMock ` otherwise.
1327+ If :func: `patch ` is used as a decorator and *new * is
13261328 omitted, the created mock is passed in as an extra argument to the
13271329 decorated function. If :func: `patch ` is used as a context manager the created
13281330 mock is returned by the context manager.
@@ -1340,8 +1342,8 @@ patch
13401342 patch to pass in the object being mocked as the spec/spec_set object.
13411343
13421344 *new_callable * allows you to specify a different class, or callable object,
1343- that will be called to create the *new * object. By default :class: `MagicMock ` is
1344- used.
1345+ that will be called to create the *new * object. By default :class: `AsyncMock `
1346+ is used for async functions and :class: ` MagicMock ` for the rest .
13451347
13461348 A more powerful form of *spec * is *autospec *. If you set ``autospec=True ``
13471349 then the mock will be created with a spec from the object being replaced.
@@ -1505,6 +1507,10 @@ work as expected::
15051507 ...
15061508 >>> test()
15071509
1510+ .. versionchanged :: 3.8
1511+
1512+ :func: `patch ` now returns an :class: `AsyncMock ` if the target is an async function.
1513+
15081514
15091515patch.object
15101516~~~~~~~~~~~~
@@ -2289,6 +2295,12 @@ See :ref:`auto-speccing` for examples of how to use auto-speccing with
22892295:func: `create_autospec ` and the *autospec * argument to :func: `patch `.
22902296
22912297
2298+ .. versionchanged :: 3.8
2299+
2300+ :func: `create_autospec ` now returns an :class: `AsyncMock ` if the target is
2301+ an async function.
2302+
2303+
22922304ANY
22932305~~~
22942306
0 commit comments