PyDocs

Nav

Development Tools

AsyncMock.assert_has_awaits

  • AsyncMock.assert_has_awaits(calls, any_order=False)
Assert the mock has been awaited with the specified calls.
The :attr:`await_args_list` list is checked for the awaits.

If `any_order` is False (the default) then the awaits must be
sequential. There can be extra calls before or after the
specified awaits.

If `any_order` is True then the awaits can be in any order, but
they must all appear in :attr:`await_args_list`.
1 Example
>>> mock = AsyncMock()
>>> async def main(*args, **kwargs):
...     await mock(*args, **kwargs)
...
>>> calls = [call("foo"), call("bar")]
>>> mock.assert_has_awaits(calls)
Traceback (most recent call last):
...
AssertionError: Awaits not found.
Expected: [call('foo'), call('bar')]
Actual: []
>>> asyncio.run(main('foo'))
>>> asyncio.run(main('bar'))
>>> mock.assert_has_awaits(calls)
from the Python docs
See Also
No see-alsos for unittest.mock/AsyncMock.assert_has_awaits
0 Notes
No notes for AsyncMock.assert_has_awaits