anydi 0.35.0__tar.gz → 0.36.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {anydi-0.35.0 → anydi-0.36.0}/PKG-INFO +1 -1
- {anydi-0.35.0 → anydi-0.36.0}/anydi/_container.py +6 -4
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/pytest_plugin.py +33 -15
- {anydi-0.35.0 → anydi-0.36.0}/pyproject.toml +1 -1
- {anydi-0.35.0 → anydi-0.36.0}/LICENSE +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/README.md +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/__init__.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/_context.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/_provider.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/_types.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/_utils.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/__init__.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/_utils.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/django/__init__.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/django/_container.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/django/_settings.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/django/_utils.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/django/apps.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/django/middleware.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/django/ninja/__init__.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/django/ninja/_operation.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/django/ninja/_signature.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/fastapi.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/faststream.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/pydantic_settings.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/starlette/__init__.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/ext/starlette/middleware.py +0 -0
- {anydi-0.35.0 → anydi-0.36.0}/anydi/py.typed +0 -0
|
@@ -536,8 +536,9 @@ class Container:
|
|
|
536
536
|
instance = context.get(provider.interface)
|
|
537
537
|
if instance is None:
|
|
538
538
|
instance = self._create_instance(provider, context)
|
|
539
|
-
|
|
540
|
-
|
|
539
|
+
if not self._override_instances:
|
|
540
|
+
context.set(provider.interface, instance)
|
|
541
|
+
return instance, True
|
|
541
542
|
return instance, False
|
|
542
543
|
|
|
543
544
|
async def _aget_or_create_instance(
|
|
@@ -547,8 +548,9 @@ class Container:
|
|
|
547
548
|
instance = context.get(provider.interface)
|
|
548
549
|
if instance is None:
|
|
549
550
|
instance = await self._acreate_instance(provider, context)
|
|
550
|
-
|
|
551
|
-
|
|
551
|
+
if not self._override_instances:
|
|
552
|
+
context.set(provider.interface, instance)
|
|
553
|
+
return instance, True
|
|
552
554
|
return instance, False
|
|
553
555
|
|
|
554
556
|
def _create_instance(
|
|
@@ -6,6 +6,8 @@ from collections.abc import Iterator
|
|
|
6
6
|
from typing import Any, Callable, cast
|
|
7
7
|
|
|
8
8
|
import pytest
|
|
9
|
+
from _pytest.python import async_warn_and_skip
|
|
10
|
+
from anyio.pytest_plugin import extract_backend_and_options, get_runner
|
|
9
11
|
|
|
10
12
|
from anydi import Container
|
|
11
13
|
from anydi._utils import get_typed_parameters
|
|
@@ -113,28 +115,44 @@ def _anydi_inject(
|
|
|
113
115
|
|
|
114
116
|
|
|
115
117
|
@pytest.fixture(autouse=True)
|
|
116
|
-
|
|
118
|
+
def _anydi_ainject(
|
|
117
119
|
request: pytest.FixtureRequest,
|
|
118
120
|
_anydi_should_inject: bool,
|
|
119
121
|
_anydi_injected_parameter_iterator: Callable[[], Iterator[tuple[str, Any]]],
|
|
120
122
|
_anydi_unresolved: list[str],
|
|
121
123
|
) -> None:
|
|
122
124
|
"""Inject dependencies into the test function."""
|
|
123
|
-
if
|
|
125
|
+
if (
|
|
126
|
+
not inspect.iscoroutinefunction(request.function)
|
|
127
|
+
and not inspect.isasyncgenfunction(request.function)
|
|
128
|
+
or not _anydi_should_inject
|
|
129
|
+
):
|
|
124
130
|
return
|
|
125
131
|
|
|
126
|
-
#
|
|
127
|
-
|
|
132
|
+
# Skip if the anyio backend is not available
|
|
133
|
+
if "anyio_backend" not in request.fixturenames:
|
|
134
|
+
async_warn_and_skip(request.node.nodeid)
|
|
128
135
|
|
|
129
|
-
|
|
130
|
-
#
|
|
131
|
-
|
|
132
|
-
continue
|
|
136
|
+
async def _awrapper() -> None:
|
|
137
|
+
# Setup the container
|
|
138
|
+
container = cast(Container, request.getfixturevalue("anydi_setup_container"))
|
|
133
139
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
for argname, interface in _anydi_injected_parameter_iterator():
|
|
141
|
+
# Skip if the interface is not registered
|
|
142
|
+
if container.strict and not container.is_registered(interface):
|
|
143
|
+
continue
|
|
144
|
+
|
|
145
|
+
try:
|
|
146
|
+
request.node.funcargs[argname] = await container.aresolve(interface)
|
|
147
|
+
except Exception as exc:
|
|
148
|
+
logger.warning(
|
|
149
|
+
f"Failed to resolve dependency for argument '{argname}'.",
|
|
150
|
+
exc_info=exc,
|
|
151
|
+
)
|
|
152
|
+
_anydi_unresolved.append(interface)
|
|
153
|
+
|
|
154
|
+
anyio_backend = request.getfixturevalue("anyio_backend")
|
|
155
|
+
backend_name, backend_options = extract_backend_and_options(anyio_backend)
|
|
156
|
+
|
|
157
|
+
with get_runner(backend_name, backend_options) as runner:
|
|
158
|
+
runner.run_fixture(_awrapper, {})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|