From 19081b834991d263d84c761dcf422a8c9faf40a1 Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Wed, 31 Jul 2013 12:01:49 -0500 Subject: Clear out the dependency registry between tests As part of the process during several tests setUp where the backends are reloaded, automatic dependency injection takes place. The REGISTRY is being updated with new providers and it's also looking up the required dependencies. Some of the providers for the requirements may not have been updated yet with the new provider object, so it loads an object that was created from a previous test run rather than the current one. This can cause tests to fail when one class gets a ref to the old one (it depends on the order that the tests are run). This change clears out the registry of providers before loading backends. It only affects testing. Part of fix for bug 1204605 Change-Id: Ib845493fa13531225e4be7e3b6cc315b9d19a0f4 --- tests/test_injection.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/test_injection.py b/tests/test_injection.py index 4b6fc8ba..08ccd7c7 100644 --- a/tests/test_injection.py +++ b/tests/test_injection.py @@ -165,3 +165,20 @@ class TestDependencyInjection(unittest.TestCase): with self.assertRaises(dependency.UnresolvableDependencyException): Consumer() + + def test_reset(self): + # Can reset the registry of providers. + + p_id = uuid.uuid4().hex + + @dependency.provider(p_id) + class P(object): + pass + + p_inst = P() + + self.assertIs(dependency.REGISTRY[p_id], p_inst) + + dependency.reset() + + self.assertFalse(dependency.REGISTRY) -- cgit