Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

different calls to provide() in a singleton scope do not return a singletonΒ #43

@jfaleiro

Description

@jfaleiro

This test should not fail, i.e., a and b.a should be the same instance in a singleton scope:

   def test_graph_creation_with_binding_to_instance(self):
        class A:
            def do(self):
                return 1

        class B:                
            def __init__(self, a):
                self.a = a

        class Binding(BindingSpec):
            def configure(self, bind):
                bind('a', to_instance=A())
             

        graph = new_object_graph(classes=[A, B], binding_specs=[Binding()])
        a = graph.provide(A)
        self.assertEqual(1, a.do())

        b = graph.provide(B)
        self.assertEqual(1, b.a.do())        

        self.assertIs(a, b.a)

The last assertion fails:

AssertionError: <test_injection.Test.test_graph_creation_with_binding.<locals>.A object at 0x10422f310> is not <test_injection.Test.test_graph_creation_with_binding.<locals>.A object at 0x1043fa2d0>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions