I am using repoze.depinj in a small project to help replace a backend database with a dummy version. I was puzzled for quite some time by my code sometimes getting my test dummy and sometimes getting the real database. I finally tracked this down to something unexpected in repoze.depinj: every call to lookup() removes an inserted dummy. Since my code calls the backend at several places, I ended up having to do multiple inject() calls in my test. My functional test base class now looks like this:

    def setUp(self):
        from repoze.depinj import inject
        from customer.portal.run import main
        from customer.portal.backend import get_backend
        from infrae.testbrowser.browser import Browser
        self.backend = DummyBackend()

        def dummy_get_backend(request):
            return self.backend

        # Every lookup() removes an injection, so inject many times
        # to make sure multiple get_backend() calls are covered
        for i in range(50):
            inject(dummy_get_backend, get_backend)
        self.app = main({})
        self.browser = Browser(self.app)

this works, but is not very pleasant. I could not find any hint in the repoze.depinj documentation that lookup() is supposed to remove an override. Is that really the intended behaviour?


Repoze-dev mailing list

Reply via email to