Skip to content

Commit 631375b

Browse files
committed
test: Multibound scopes are isolated
1 parent 1fb1c90 commit 631375b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

injector_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,25 @@ def configure(binder: Binder) -> None:
754754
assert first_list[2] is second_list[2]
755755

756756

757+
def test_multibind_list_scopes_applies_to_the_bound_items_in_the_multibound_list() -> None:
758+
SingletonPlugins = Annotated[Plugin, "singleton"]
759+
OtherPlugins = Annotated[Plugin, "other"]
760+
761+
def configure(binder: Binder) -> None:
762+
binder.multibind(List[SingletonPlugins], to=PluginA, scope=singleton)
763+
binder.multibind(List[OtherPlugins], to=PluginA)
764+
765+
injector = Injector([configure])
766+
singletons_1 = injector.get(List[SingletonPlugins])
767+
singletons_2 = injector.get(List[SingletonPlugins])
768+
others_1 = injector.get(List[OtherPlugins])
769+
others_2 = injector.get(List[OtherPlugins])
770+
771+
assert singletons_1[0] is singletons_2[0]
772+
assert singletons_1[0] is not others_1[0]
773+
assert others_1[0] is not others_2[0]
774+
775+
757776
def test_multibind_dict_scopes_applies_to_the_bound_items() -> None:
758777
def configure(binder: Binder) -> None:
759778
binder.multibind(Dict[str, Plugin], to={'a': PluginA}, scope=singleton)

0 commit comments

Comments
 (0)