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
« 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
5def dep() -> int: 1abcdefghijklmnopqrst
6 return 1 1abcdefghijklmnopqrst
9def func(d: int = Depends(dep)) -> int: 1abcdefghijklmnopqrst
10 return d 1abcdefghijklmnopqrst
13def test_inject_reuses_a_prebuilt_model() -> None: 1abcdefghijklmnopqrst
14 """`inject()` accepts an already built `CallModel` instead of building one.
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
22 injected = inject(None, dependency_provider=provider)(func, model) 1abcdefghijklmnopqrst
24 assert injected() == 1 1abcdefghijklmnopqrst