Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import grpc.aio
import pytest
from modern_di import Container
from modern_di.exceptions import FinalizerError

from modern_di_grpc import DIAioInterceptor, FromDI, fetch_di_container, grpc_context_provider, inject
from modern_di_grpc.main import _request_container, _wrap_unary_aio
Expand Down Expand Up @@ -160,8 +161,11 @@ async def behavior(_request: object, _context: grpc.aio.ServicerContext) -> str:
wrapped = _wrap_unary_aio(behavior, root)
context = typing.cast(grpc.aio.ServicerContext, unittest.mock.MagicMock(spec=grpc.ServicerContext))

with pytest.raises(RuntimeError, match="boom"):
with pytest.raises(FinalizerError) as exc_info:
await wrapped(object(), context)
[error] = exc_info.value.exceptions
assert isinstance(error, RuntimeError)
assert str(error) == "boom"

with pytest.raises(LookupError):
_request_container.get()
Expand Down
6 changes: 5 additions & 1 deletion tests/test_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest
from grpc import ServicerContext
from modern_di import Container, Scope
from modern_di.exceptions import FinalizerError

from modern_di_grpc import DIAioInterceptor, DIInterceptor, FromDI, fetch_di_container, grpc_context_provider, inject
from modern_di_grpc.main import _build_child, _request_container, _wrap_unary_sync
Expand Down Expand Up @@ -175,8 +176,11 @@ def behavior(_request: object, _context: ServicerContext) -> str:
wrapped = _wrap_unary_sync(behavior, root)
context = typing.cast(ServicerContext, unittest.mock.MagicMock(spec=ServicerContext))

with pytest.raises(RuntimeError, match="boom"):
with pytest.raises(FinalizerError) as exc_info:
wrapped(object(), context)
[error] = exc_info.value.exceptions
assert isinstance(error, RuntimeError)
assert str(error) == "boom"

# Reset ran despite child.close_sync() raising: the ContextVar is unset again, not just
# left pointing at a stale/closed child container.
Expand Down
Loading