Skip to content

Commit a6f97e9

Browse files
committed
fixed regex error and testModule not finding internal services
1 parent a1e2426 commit a6f97e9

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

ellar/di/scopes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ def get(self, key: t.Type[T], provider: Provider[T]) -> Provider[T]:
3434
scoped_context = self.get_context()
3535

3636
if scoped_context is None:
37-
raise UnsatisfiedRequirement(None, key)
37+
raise Exception(
38+
"RequestScope is not available. Trying to access RequestScope outside request",
39+
UnsatisfiedRequirement(None, key),
40+
)
3841
try:
3942
return scoped_context.context[key]
4043
except KeyError:

ellar/testing/module.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ def get_test_client(
9494
)
9595

9696
def get(self, interface: t.Type[T]) -> T:
97+
# try to find module to which the interface belongs
98+
module = self.create_application().injector.tree_manager.search_module_tree(
99+
filter_item=lambda data: True,
100+
find_predicate=lambda data: interface in data.exports
101+
or interface in data.providers,
102+
)
103+
if module:
104+
return t.cast(T, module.value.get(interface))
97105
return self.create_application().injector.get(interface) # type: ignore[no-any-return]
98106

99107

requirements-tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pytest-asyncio
1313
pytest-cov >= 2.12.0,< 6.0.0
1414
python-multipart >= 0.0.5
1515
python-socketio
16+
regex==2024.11.6
1617
ruff ==0.6.3
1718
types-dataclasses ==0.6.6
1819
types-orjson ==3.6.2

0 commit comments

Comments
 (0)