Skip to content

Commit

Permalink
Remove coverage ignore in inject
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirVondukr committed Oct 19, 2023
1 parent 97f068d commit 110c50e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aioinject/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 17 additions & 0 deletions tests/test_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit 110c50e

Please sign in to comment.