From 291aac013df6441dea88d5bb7d83b168c15a03e5 Mon Sep 17 00:00:00 2001 From: Lisa Roach Date: Mon, 9 Sep 2019 12:29:49 +0100 Subject: [PATCH 1/4] bpo-351428: Updates documentation to reflect AsyncMock call_count after await. --- Doc/library/unittest.mock.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 304ba532274ddb..9d7ceb8c84cee1 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -514,6 +514,18 @@ 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() + >>> mock.call_count + 0 + >>> async def main(): + >>> await mock() + >>> asyncio.run(main()) + >>> mock.call_count + 1 .. attribute:: return_value From 14e16d3e865b011fd94d581ea46ee6b05fad9786 Mon Sep 17 00:00:00 2001 From: Lisa Roach Date: Mon, 9 Sep 2019 15:00:01 +0100 Subject: [PATCH 2/4] Adds skip and fixes warning. --- Doc/library/unittest.mock.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 9d7ceb8c84cee1..9b874062b9f193 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -518,7 +518,8 @@ the *new_callable* argument to :func:`patch`. has been awaited: >>> mock = AsyncMock() - >>> mock() + >>> mock() # doctest: +SKIP + >>> >>> mock.call_count 0 >>> async def main(): From f5cafc3f69d4aaacef167f192b4e1d9b0cf0dcaf Mon Sep 17 00:00:00 2001 From: Lisa Roach Date: Mon, 9 Sep 2019 15:25:38 +0100 Subject: [PATCH 3/4] Removes extra >>>. --- Doc/library/unittest.mock.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 9b874062b9f193..88fbe36f1e0092 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -519,7 +519,7 @@ the *new_callable* argument to :func:`patch`. >>> mock = AsyncMock() >>> mock() # doctest: +SKIP - >>> + >>> mock.call_count 0 >>> async def main(): From 5029d66d649110729a1f1cf8e8b74df2ee2a3b0e Mon Sep 17 00:00:00 2001 From: Lisa Roach Date: Mon, 9 Sep 2019 16:06:10 +0100 Subject: [PATCH 4/4] Adds ... in front of await mock(). --- Doc/library/unittest.mock.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 88fbe36f1e0092..b2547546f3d6d7 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -523,7 +523,8 @@ the *new_callable* argument to :func:`patch`. >>> mock.call_count 0 >>> async def main(): - >>> await mock() + ... await mock() + ... >>> asyncio.run(main()) >>> mock.call_count 1