summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/unittest.mock.rst28
1 files changed, 27 insertions, 1 deletions
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst
index 300f28c..3fa3cfd 100644
--- a/Doc/library/unittest.mock.rst
+++ b/Doc/library/unittest.mock.rst
@@ -865,7 +865,7 @@ object::
True
The result of ``mock()`` is an async function which will have the outcome
- of ``side_effect`` or ``return_value``:
+ of ``side_effect`` or ``return_value`` after it has been awaited:
- if ``side_effect`` is a function, the async function will return the
result of that function,
@@ -890,6 +890,32 @@ object::
>>> mock() # doctest: +SKIP
<coroutine object AsyncMockMixin._mock_call at ...>
+
+ Setting the *spec* of a :class:`Mock`, :class:`MagicMock`, or :class:`AsyncMock`
+ to a class with asynchronous and synchronous functions will automatically
+ detect the synchronous functions and set them as :class:`MagicMock` (if the
+ parent mock is :class:`AsyncMock` or :class:`MagicMock`) or :class:`Mock` (if
+ the parent mock is :class:`Mock`). All asynchronous functions will be
+ :class:`AsyncMock`.
+
+ >>> class ExampleClass:
+ ... def sync_foo():
+ ... pass
+ ... async def async_foo():
+ ... pass
+ ...
+ >>> a_mock = AsyncMock(ExampleClass)
+ >>> a_mock.sync_foo
+ <MagicMock name='mock.sync_foo' id='...'>
+ >>> a_mock.async_foo
+ <AsyncMock name='mock.async_foo' id='...'>
+ >>> mock = Mock(ExampleClass)
+ >>> mock.sync_foo
+ <Mock name='mock.sync_foo' id='...'>
+ >>> mock.async_foo
+ <AsyncMock name='mock.async_foo' id='...'>
+
+
.. method:: assert_awaited()
Assert that the mock was awaited at least once. Note that this is separate