You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default AsyncMock doesn't provide any proper mocking of async
async iterators, and if we just assign a `AsyncMock` to stub calls like
`ReceivePublicTradesStream`, what happens is that
`async for x in ReceivePublicTradesStream()` is used instead. What
Python does with this is something like:
```py
stream = ReceivePublicTradesStream()
it = stream.__aiter__() # Gets an anync iterator, but this call is sync
while v := await it.__anext():
...
```
Because `ReceivePublicTradesStream` is an `AsyncMock`, getting any
attributes (like `__aiter__()`) results in returning a new `AsyncMock`.
But since `__aiter__()` is called without an `await`, then we get the
following exceptions/warnings:
* TypeError("'async for' requires an object with __aiter__ method, got
coroutine")
* RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was
never awaited
To fix this, we just crate a proper fake async iterator we can return
to the async mock.
Signed-off-by: Leandro Lucarella <[email protected]>
0 commit comments