from unittest.mock import AsyncMock async def some_async_function(): return "Async function" async_mock = AsyncMock(return_value="Mocked value") result = await async_mock() assert result == "Mocked value"
from unittest.mock import AsyncMock async def some_async_function(x: int): return x + 1 async_mock = AsyncMock(side_effect=lambda x: x * 2) result = await async_mock(2) assert result == 4In this example, we create an `AsyncMock` object with a `side_effect` that multiplies the input by 2. We then call the mock coroutine function with an input of 2 and assert that the result is equal to 4. The `AsyncMock` class is part of the standard `unittest.mock` library in Python.