Skip to content

Commit 2c9fbae

Browse files
committed
Clean up after ImportModulePoisonFixture
ImportModulePoisonFixture installs a MetaPathFinder to sys.meta_path to catch unsuitable imports during testing. But the extra finder wasn't removed during fixture cleanup so such finder is leaked between test cases running in the same test executor. As all our test cases has this poison set up by default this only caused unnecessary finders accumulating in sys.meta_path. Change-Id: I2692552000687d51158dad0d938d68e891b40d8a
1 parent 3eb23d3 commit 2c9fbae

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

nova/tests/fixtures/nova.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,14 +1832,16 @@ def __init__(self, module_names):
18321832
self.module_names = module_names
18331833
self.fail_message = ''
18341834
if isinstance(module_names, str):
1835-
self.module_names = set([module_names])
1836-
sys.meta_path.insert(0, self.ForbiddenModules(self, self.module_names))
1835+
self.module_names = {module_names}
1836+
self.meta_path_finder = self.ForbiddenModules(self, self.module_names)
18371837

18381838
def setUp(self):
18391839
super().setUp()
18401840
self.addCleanup(self.cleanup)
1841+
sys.meta_path.insert(0, self.meta_path_finder)
18411842

18421843
def cleanup(self):
1844+
sys.meta_path.remove(self.meta_path_finder)
18431845
# We use a flag and check it during the cleanup phase to fail the test
18441846
# if needed. This is done because some module imports occur inside of a
18451847
# try-except block that ignores all exceptions, so raising an exception

0 commit comments

Comments
 (0)