diff options
author | Lisa Roach <lisaroach14@gmail.com> | 2019-09-24 03:49:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-24 03:49:40 (GMT) |
commit | ef048517755db1f0d211fb6dfc655a8b412cc96f (patch) | |
tree | 20c1dd5ef9c6dbcd529122ed378878954df63ebd /Doc/library | |
parent | 6f53d34fb0f944a8c0ee530334c353559ac40f72 (diff) | |
download | cpython-ef048517755db1f0d211fb6dfc655a8b412cc96f.zip cpython-ef048517755db1f0d211fb6dfc655a8b412cc96f.tar.gz cpython-ef048517755db1f0d211fb6dfc655a8b412cc96f.tar.bz2 |
bpo-38136: Updates await_count and call_count to be different things (GH-16192)
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/unittest.mock.rst | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index b446ddb..300f28c 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -514,21 +514,6 @@ 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 Set this to configure the value returned by calling the mock: @@ -907,19 +892,22 @@ object:: .. method:: assert_awaited() - Assert that the mock was awaited at least once. + Assert that the mock was awaited at least once. Note that this is separate + from the object having been called, the ``await`` keyword must be used: >>> mock = AsyncMock() - >>> async def main(): - ... await mock() + >>> async def main(coroutine_mock): + ... await coroutine_mock ... - >>> asyncio.run(main()) + >>> coroutine_mock = mock() + >>> mock.called + True >>> mock.assert_awaited() - >>> mock_2 = AsyncMock() - >>> mock_2.assert_awaited() Traceback (most recent call last): ... AssertionError: Expected mock to have been awaited. + >>> asyncio.run(main(coroutine_mock)) + >>> mock.assert_awaited() .. method:: assert_awaited_once() @@ -1004,14 +992,15 @@ object:: ... await mock(*args, **kwargs) ... >>> calls = [call("foo"), call("bar")] - >>> mock.assert_has_calls(calls) + >>> mock.assert_has_awaits(calls) Traceback (most recent call last): ... - AssertionError: Calls not found. + AssertionError: Awaits not found. Expected: [call('foo'), call('bar')] + Actual: [] >>> asyncio.run(main('foo')) >>> asyncio.run(main('bar')) - >>> mock.assert_has_calls(calls) + >>> mock.assert_has_awaits(calls) .. method:: assert_not_awaited() |