]> granicus.if.org Git - python/commitdiff
bpo-37383: Updates docs to reflect AsyncMock call_count after await. (GH-15761)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 10 Sep 2019 07:31:34 +0000 (00:31 -0700)
committerGitHub <noreply@github.com>
Tue, 10 Sep 2019 07:31:34 +0000 (00:31 -0700)
* bpo-351428: Updates documentation to reflect AsyncMock call_count after await.

* Adds skip and fixes warning.

* Removes extra >>>.

* Adds ... in front of await mock().
(cherry picked from commit b9f65f01fd761da7799f36d29b54518399d3458e)

Co-authored-by: Lisa Roach <lisaroach14@gmail.com>
Doc/library/unittest.mock.rst

index 304ba532274ddb03a885de263354a009bdb66f0c..b2547546f3d6d7722aa2b33920a19ce7c8d71232 100644 (file)
@@ -514,6 +514,20 @@ the *new_callable* argument to :func:`patch`.
             >>> mock.call_count
             2
 
+        For :class:`AsyncMock` the :attr:`call_count` is only iterated if the function
+        has been awaited:
+
+            >>> mock = AsyncMock()
+            >>> mock()  # doctest: +SKIP
+            <coroutine object AsyncMockMixin._mock_call at ...>
+            >>> mock.call_count
+            0
+            >>> async def main():
+            ...     await mock()
+            ...
+            >>> asyncio.run(main())
+            >>> mock.call_count
+            1
 
     .. attribute:: return_value