Skip to content

Commit b27bbff

Browse files
author
remimd
committed
tests
1 parent f531fd3 commit b27bbff

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/test_injectable.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,18 @@ def my_enum_recipe() -> MyEnum:
229229

230230
value = get_instance(MyEnum)
231231
assert isinstance(value, MyEnum)
232+
233+
async def test_injectable_with_circular_dependency_raise_recursion_error(self):
234+
class A: ...
235+
236+
@injectable
237+
@dataclass
238+
class B:
239+
a: A
240+
241+
@injectable
242+
async def a_factory(_b: B) -> A:
243+
return A()
244+
245+
with pytest.raises(RecursionError):
246+
await aget_instance(A)

tests/test_singleton.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,18 @@ class C(B): ...
183183

184184
a = get_instance(A)
185185
assert isinstance(a, C)
186+
187+
async def test_singleton_with_circular_dependency_raise_recursion_error(self):
188+
class A: ...
189+
190+
@singleton
191+
@dataclass
192+
class B:
193+
a: A
194+
195+
@singleton
196+
async def a_factory(_b: B) -> A:
197+
return A()
198+
199+
with pytest.raises(RecursionError):
200+
await aget_instance(A)

0 commit comments

Comments
 (0)