當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python unittest.mock.AsyncMock.assert_awaited_once_with用法及代碼示例


用法:

assert_awaited_once_with(*args, **kwargs)

斷言模擬隻等待了一次並使用指定的參數。

>>> mock = AsyncMock()
>>> async def main(*args, **kwargs):
...     await mock(*args, **kwargs)
...
>>> asyncio.run(main('foo', bar='bar'))
>>> mock.assert_awaited_once_with('foo', bar='bar')
>>> asyncio.run(main('foo', bar='bar'))
>>> mock.assert_awaited_once_with('foo', bar='bar')
Traceback (most recent call last):
...
AssertionError: Expected mock to have been awaited once. Awaited 2 times.

相關用法


注:本文由純淨天空篩選整理自python.org大神的英文原創作品 unittest.mock.AsyncMock.assert_awaited_once_with。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。