]> granicus.if.org Git - python/commitdiff
bpo-37383: Updates docs to reflect AsyncMock call_count after await. (#15761)
authorLisa Roach <lisaroach14@gmail.com>
Mon, 9 Sep 2019 16:54:13 +0000 (17:54 +0100)
committerGitHub <noreply@github.com>
Mon, 9 Sep 2019 16:54:13 +0000 (17:54 +0100)
* bpo-351428: Updates documentation to reflect AsyncMock call_count after await.

* Adds skip and fixes warning.

* Removes extra >>>.

* Adds ... in front of await mock().

Doc/library/unittest.mock.rst

index 9bb342773a9759a645ef0486e054b7bf421feb28..04ff8a61da3c563843bb48d09bb2efb86f154724 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