Skip to content

Commit b9f65f0

Browse files
authored
bpo-37383: Updates docs to reflect AsyncMock call_count after await. (#15761)
* bpo-351428: Updates documentation to reflect AsyncMock call_count after await. * Adds skip and fixes warning. * Removes extra >>>. * Adds ... in front of await mock().
1 parent d14e39c commit b9f65f0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Doc/library/unittest.mock.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,20 @@ the *new_callable* argument to :func:`patch`.
514514
>>> mock.call_count
515515
2
516516

517+
For :class:`AsyncMock` the :attr:`call_count` is only iterated if the function
518+
has been awaited:
519+
520+
>>> mock = AsyncMock()
521+
>>> mock() # doctest: +SKIP
522+
<coroutine object AsyncMockMixin._mock_call at ...>
523+
>>> mock.call_count
524+
0
525+
>>> async def main():
526+
... await mock()
527+
...
528+
>>> asyncio.run(main())
529+
>>> mock.call_count
530+
1
517531

518532
.. attribute:: return_value
519533

0 commit comments

Comments
 (0)