mocksafe.when_async

mocksafe.when_async(mock_callable: Callable[[...], Coroutine[Any, Any, T]]) WhenStubber[T]

Stub a mocked async method / Callable.

This is the async counterpart to when(). Use it when stubbing async methods so that MatchCallStubber.then_return() accepts the awaited return type directly rather than a coroutine.

Parameters:

mock_callable – a mocked async method / Callable

Return type:

WhenStubber[T]

Example:
>>> when_async(mock_svc.fetch).any_call().then_return("result")