From 110c50ea018e5ff3828d7da99e91cf6a921f7d26 Mon Sep 17 00:00:00 2001 From: Doctor Date: Thu, 19 Oct 2023 18:54:28 +0300 Subject: [PATCH] Remove coverage ignore in `inject` --- aioinject/decorators.py | 2 +- tests/test_inject.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/aioinject/decorators.py b/aioinject/decorators.py index adcaca5..43bf51c 100644 --- a/aioinject/decorators.py +++ b/aioinject/decorators.py @@ -140,6 +140,6 @@ def wrap(function: Callable[_P, _T]) -> Callable[_P, _T]: return _wrap_sync(function, inject_method=inject_method) if func is None: - return wrap # pragma: no cover + return wrap return wrap(func) diff --git a/tests/test_inject.py b/tests/test_inject.py index 1943396..5d905b2 100644 --- a/tests/test_inject.py +++ b/tests/test_inject.py @@ -3,6 +3,8 @@ import pytest from aioinject import Container, Inject, inject, providers +from aioinject.context import container_var +from aioinject.decorators import InjectMethod class _Session: @@ -130,3 +132,18 @@ async def test_service_with_multiple_dependencies_with_same_type( service = await ctx.resolve(_NeedsMultipleImplementations) assert isinstance(service.a, _ImplementationA) assert isinstance(service.b, _ImplementationB) + + +@pytest.mark.anyio +async def test_inject_using_container( + container: Container, +) -> None: + @inject(inject_method=InjectMethod.container) + async def injectee(service: Annotated[_Service, Inject]) -> _Service: + return service + + token = container_var.set(container) + # This is fine + coro = injectee() # type: ignore[call-arg] + assert isinstance(await coro, _Service) + container_var.reset(token)