Coverage for tests/test_inject.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-13 05:19 +0000

1from fast_depends import Depends, Provider, inject 1abcdefghijklmnopqrst

2from fast_depends.core import build_call_model 1abcdefghijklmnopqrst

3 

4 

5def dep() -> int: 1abcdefghijklmnopqrst

6 return 1 1abcdefghijklmnopqrst

7 

8 

9def func(d: int = Depends(dep)) -> int: 1abcdefghijklmnopqrst

10 return d 1abcdefghijklmnopqrst

11 

12 

13def test_inject_reuses_a_prebuilt_model() -> None: 1abcdefghijklmnopqrst

14 """`inject()` accepts an already built `CallModel` instead of building one. 

15 

16 This is what integrations (e.g. FastStream) rely on to build the model once, 

17 inspect it, and only then wrap the call. 

18 """ 

19 provider = Provider() 1abcdefghijklmnopqrst

20 model = build_call_model(func, dependency_provider=provider) 1abcdefghijklmnopqrst

21 

22 injected = inject(None, dependency_provider=provider)(func, model) 1abcdefghijklmnopqrst

23 

24 assert injected() == 1 1abcdefghijklmnopqrst