@@ -1307,8 +1307,10 @@ patch
13071307 is patched with a *new * object. When the function/with statement exits
13081308 the patch is undone.
13091309
1310- If *new * is omitted, then the target is replaced with a
1311- :class: `MagicMock `. If :func: `patch ` is used as a decorator and *new * is
1310+ If *new * is omitted, then the target is replaced with an
1311+ :class: `AsyncMock ` if the patched object is an async function or
1312+ a :class: `MagicMock ` otherwise.
1313+ If :func: `patch ` is used as a decorator and *new * is
13121314 omitted, the created mock is passed in as an extra argument to the
13131315 decorated function. If :func: `patch ` is used as a context manager the created
13141316 mock is returned by the context manager.
@@ -1326,8 +1328,8 @@ patch
13261328 patch to pass in the object being mocked as the spec/spec_set object.
13271329
13281330 *new_callable * allows you to specify a different class, or callable object,
1329- that will be called to create the *new * object. By default :class: `MagicMock ` is
1330- used.
1331+ that will be called to create the *new * object. By default :class: `AsyncMock `
1332+ is used for async functions and :class: ` MagicMock ` for the rest .
13311333
13321334 A more powerful form of *spec * is *autospec *. If you set ``autospec=True ``
13331335 then the mock will be created with a spec from the object being replaced.
@@ -1491,6 +1493,10 @@ work as expected::
14911493 ...
14921494 >>> test()
14931495
1496+ .. versionchanged :: 3.8
1497+
1498+ :func: `patch ` now returns an :class: `AsyncMock ` if the target is an async function.
1499+
14941500
14951501patch.object
14961502~~~~~~~~~~~~
@@ -2275,6 +2281,12 @@ See :ref:`auto-speccing` for examples of how to use auto-speccing with
22752281:func: `create_autospec ` and the *autospec * argument to :func: `patch `.
22762282
22772283
2284+ .. versionchanged :: 3.8
2285+
2286+ :func: `create_autospec ` now returns an :class: `AsyncMock ` if the target is
2287+ an async function.
2288+
2289+
22782290ANY
22792291~~~
22802292
0 commit comments