summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/importlib/test/util.py')
-rw-r--r--Lib/importlib/test/util.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/importlib/test/util.py b/Lib/importlib/test/util.py
index 0c0c84c..93b7cd2 100644
--- a/Lib/importlib/test/util.py
+++ b/Lib/importlib/test/util.py
@@ -84,8 +84,9 @@ class mock_modules:
"""A mock importer/loader."""
- def __init__(self, *names):
+ def __init__(self, *names, module_code={}):
self.modules = {}
+ self.module_code = {}
for name in names:
if not name.endswith('.__init__'):
import_name = name
@@ -105,6 +106,8 @@ class mock_modules:
if import_name != name:
module.__path__ = ['<mock __path__>']
self.modules[import_name] = module
+ if import_name in module_code:
+ self.module_code[import_name] = module_code[import_name]
def __getitem__(self, name):
return self.modules[name]
@@ -120,6 +123,8 @@ class mock_modules:
raise ImportError
else:
sys.modules[fullname] = self.modules[fullname]
+ if fullname in self.module_code:
+ self.module_code[fullname]()
return self.modules[fullname]
def __enter__(self):