Skip to content

Commit d182af1

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Clean up after ImportModulePoisonFixture"
2 parents c6ba099 + 2c9fbae commit d182af1

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)