Iterate over copy of sys.modules keys in Python2/3
Iterate over a copy of sys.modules keys in both Python 2.x and Python 3.x. In Python 3.x, keys() is not a copy, and therefore items can't be popped from it while iterating. Change-Id: I98c3d7695bbfe3a6a4f23990af45a07dc147f22f Closes-Bug: #1463503
This commit is contained in:
@@ -179,7 +179,7 @@ class DisableModuleFixture(fixtures.Fixture):
|
||||
|
||||
def clear_module(self):
|
||||
cleared_modules = {}
|
||||
for fullname in sys.modules.keys():
|
||||
for fullname in list(sys.modules):
|
||||
if (fullname == self.module or
|
||||
fullname.startswith(self.module + '.')):
|
||||
cleared_modules[fullname] = sys.modules.pop(fullname)
|
||||
|
||||
Reference in New Issue
Block a user