anydi 0.37.4a0__py3-none-any.whl → 0.38.1__py3-none-any.whl

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/_container.py CHANGED
@@ -504,6 +504,8 @@ class Container:
504
504
  instance = self._create_instance(provider, context, **defaults)
505
505
  else:
506
506
  instance = self._create_instance(provider, context, **defaults)
507
+ if self.testing:
508
+ instance = self._patch_test_resolver(provider.interface, instance)
507
509
  return cast(T, instance)
508
510
 
509
511
  async def acreate(self, interface: type[T], **defaults: Any) -> T:
@@ -520,6 +522,8 @@ class Container:
520
522
  )
521
523
  else:
522
524
  instance = await self._acreate_instance(provider, context, **defaults)
525
+ if self.testing:
526
+ instance = self._patch_test_resolver(provider.interface, instance)
523
527
  return cast(T, instance)
524
528
 
525
529
  def _get_or_create_instance(
@@ -57,27 +57,20 @@ def _anydi_should_inject(request: pytest.FixtureRequest) -> bool:
57
57
  return marker is not None or inject_all
58
58
 
59
59
 
60
- @pytest.fixture(scope="session")
61
- def _anydi_unresolved() -> Iterator[list[Any]]:
62
- unresolved: list[Any] = []
63
- yield unresolved
64
- unresolved.clear()
65
-
66
-
67
60
  @pytest.fixture
68
61
  def _anydi_injected_parameter_iterator(
69
62
  request: pytest.FixtureRequest,
70
- _anydi_unresolved: list[str],
71
63
  ) -> Callable[[], Iterator[tuple[str, Any]]]:
72
- registered_fixtures = request.session._fixturemanager._arg2fixturedefs # noqa
64
+ fixturenames = set(request.node._fixtureinfo.initialnames) - set(
65
+ request.node._fixtureinfo.name2fixturedefs.keys()
66
+ )
73
67
 
74
68
  def _iterator() -> Iterator[tuple[str, inspect.Parameter]]:
75
69
  for parameter in get_typed_parameters(request.function):
76
70
  interface = parameter.annotation
77
71
  if (
78
72
  interface is inspect.Parameter.empty
79
- or interface in _anydi_unresolved
80
- or parameter.name in registered_fixtures
73
+ or parameter.name not in fixturenames
81
74
  ):
82
75
  continue
83
76
  yield parameter.name, interface
@@ -90,7 +83,6 @@ def _anydi_inject(
90
83
  request: pytest.FixtureRequest,
91
84
  _anydi_should_inject: bool,
92
85
  _anydi_injected_parameter_iterator: Callable[[], Iterator[tuple[str, Any]]],
93
- _anydi_unresolved: list[str],
94
86
  ) -> None:
95
87
  """Inject dependencies into the test function."""
96
88
 
@@ -111,7 +103,6 @@ def _anydi_inject(
111
103
  logger.warning(
112
104
  f"Failed to resolve dependency for argument '{argname}'.", exc_info=exc
113
105
  )
114
- _anydi_unresolved.append(interface)
115
106
 
116
107
 
117
108
  @pytest.fixture(autouse=True)
@@ -119,7 +110,6 @@ def _anydi_ainject(
119
110
  request: pytest.FixtureRequest,
120
111
  _anydi_should_inject: bool,
121
112
  _anydi_injected_parameter_iterator: Callable[[], Iterator[tuple[str, Any]]],
122
- _anydi_unresolved: list[str],
123
113
  ) -> None:
124
114
  """Inject dependencies into the test function."""
125
115
  if (
@@ -149,7 +139,6 @@ def _anydi_ainject(
149
139
  f"Failed to resolve dependency for argument '{argname}'.",
150
140
  exc_info=exc,
151
141
  )
152
- _anydi_unresolved.append(interface)
153
142
 
154
143
  anyio_backend = request.getfixturevalue("anyio_backend")
155
144
  backend_name, backend_options = extract_backend_and_options(anyio_backend)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anydi
3
- Version: 0.37.4a0
3
+ Version: 0.38.1
4
4
  Summary: Dependency Injection library
5
5
  Project-URL: Repository, https://github.com/antonrh/anydi
6
6
  Author-email: Anton Ruhlov <antonruhlov@gmail.com>
@@ -1,5 +1,5 @@
1
1
  anydi/__init__.py,sha256=OfRg2EfXD65pHTGQKhfkABMwUhw5LvsuTQV_Tv4V4wk,501
2
- anydi/_container.py,sha256=yH1DsSQFkbfxGaDFs47nr-iXLE_Wwgv6QMTGWrRb8cE,38524
2
+ anydi/_container.py,sha256=b2WKdDLwLj50u0DUOdAku2oYOKpw3UD7rCuytu2x_R4,38732
3
3
  anydi/_context.py,sha256=7LV_SL4QWkJeiG7_4D9PZ5lmU-MPzhofxC95zCgY9Gc,2651
4
4
  anydi/_provider.py,sha256=1IyxHO83NHjsPDHLDIZtW1pJ7i8VpWD3EM4T6duw9zA,7661
5
5
  anydi/_types.py,sha256=fdO4xNXtGMxVArmlfDkFYbyR895ixkBTW6V8lMceN7Q,1562
@@ -10,7 +10,7 @@ anydi/ext/_utils.py,sha256=U6sRqWzccWUu7eMhbXX1NrwcaxitQF9cO1KxnKF37gw,2566
10
10
  anydi/ext/fastapi.py,sha256=AEL3ubu-LxUPHMMt1YIn3En_JZC7nyBKmKxmhka3O3c,2436
11
11
  anydi/ext/faststream.py,sha256=qXnNGvAqWWp9kbhbQUE6EF_OPUiYQmtOH211_O7BI_0,1898
12
12
  anydi/ext/pydantic_settings.py,sha256=8IXXLuG_OvKbvKlBkBRQUHcXgbTpgQUxeWyoMcRIUQM,1488
13
- anydi/ext/pytest_plugin.py,sha256=ShGhiZnP1KyMHhnc9Ci1RKAuHVhw628OTS2P2BLEOfc,5001
13
+ anydi/ext/pytest_plugin.py,sha256=25A93Yon0cr4y8CszQB7zOJRiAXW-ZwtO7_Ji8mqcXs,4639
14
14
  anydi/ext/django/__init__.py,sha256=QI1IABCVgSDTUoh7M9WMECKXwB3xvh04HfQ9TOWw1Mk,223
15
15
  anydi/ext/django/_container.py,sha256=cxVoYQG16WP0S_Yv4TnLwuaaT7NVEOhLWO-YdALJUb4,418
16
16
  anydi/ext/django/_settings.py,sha256=Z0RlAuXoO73oahWeMkK10w8c-4uCBde-DBpeKTV5USY,853
@@ -22,8 +22,8 @@ anydi/ext/django/ninja/_operation.py,sha256=wSWa7D73XTVlOibmOciv2l6JHPe1ERZcXrqI
22
22
  anydi/ext/django/ninja/_signature.py,sha256=2cSzKxBIxXLqtwNuH6GSlmjVJFftoGmleWfyk_NVEWw,2207
23
23
  anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  anydi/ext/starlette/middleware.py,sha256=9CQtGg5ZzUz2gFSzJr8U4BWzwNjK8XMctm3n52M77Z0,792
25
- anydi-0.37.4a0.dist-info/METADATA,sha256=jhmqQRzY62zTNvZu6ud0UzoFmaLIH-yN9K0pHZz_dIc,4919
26
- anydi-0.37.4a0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- anydi-0.37.4a0.dist-info/entry_points.txt,sha256=Nklo9f3Oe4AkNsEgC4g43nCJ-23QDngZSVDNRMdaILI,43
28
- anydi-0.37.4a0.dist-info/licenses/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
29
- anydi-0.37.4a0.dist-info/RECORD,,
25
+ anydi-0.38.1.dist-info/METADATA,sha256=_DWptDh85lW1UwzL1AnIaCiB9THnpeaCI4AlupFYjG0,4917
26
+ anydi-0.38.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ anydi-0.38.1.dist-info/entry_points.txt,sha256=Nklo9f3Oe4AkNsEgC4g43nCJ-23QDngZSVDNRMdaILI,43
28
+ anydi-0.38.1.dist-info/licenses/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
29
+ anydi-0.38.1.dist-info/RECORD,,