diff --git a/fast_depends/core/build.py b/fast_depends/core/build.py index 626edb0..aedeaf7 100644 --- a/fast_depends/core/build.py +++ b/fast_depends/core/build.py @@ -53,7 +53,7 @@ def build_call_model( ) -> CallModel[P, T]: name = getattr(call, "__name__", type(call).__name__) - is_call_async = is_coroutine_callable(call) + is_call_async = is_coroutine_callable(call) or is_async_gen_callable(call) if is_sync is None: is_sync = not is_call_async else: diff --git a/tests/async/test_depends.py b/tests/async/test_depends.py index e2f5460..592436b 100644 --- a/tests/async/test_depends.py +++ b/tests/async/test_depends.py @@ -422,12 +422,19 @@ async def test_generator(): mock = Mock() async def func(): + mock.async_call() + + async def gen_func(): mock.start() yield mock.end() @inject - async def simple_func(a: str, d=Depends(func)) -> int: + async def simple_func( + a: str, + d=Depends(gen_func), + d2=Depends(func), + ) -> int: for _ in range(2): yield a @@ -436,6 +443,7 @@ async def simple_func(a: str, d=Depends(func)) -> int: assert not mock.end.called assert i == 1 + mock.async_call.assert_called_once() mock.end.assert_called_once()