Commit 48325b43 authored by Stefan Behnel's avatar Stefan Behnel

Modernise module loading in test runner using importlib.

parent 3bd321f1
......@@ -543,8 +543,21 @@ def _list_pyregr_data_files(test_directory):
if is_data_file(filename)]
def import_module_from_file(module_name, file_path, execute=True):
import importlib.util
spec = importlib.util.spec_from_file_location(module_name, file_path)
m = importlib.util.module_from_spec(spec)
if execute:
sys.modules[module_name] = m
spec.loader.exec_module(m)
return m
def import_ext(module_name, file_path=None):
if file_path:
if sys.version_info >= (3, 5):
return import_module_from_file(module_name, file_path)
else:
import imp
return imp.load_dynamic(module_name, file_path)
else:
......@@ -1500,9 +1513,13 @@ class PureDoctestTestCase(unittest.TestCase):
try:
self.setUp()
import imp
with self.stats.time(self.name, 'py', 'pyimport'):
if sys.version_info >= (3, 5):
m = import_module_from_file(self.module_name, self.module_path)
else:
import imp
m = imp.load_source(loaded_module_name, self.module_path)
try:
with self.stats.time(self.name, 'py', 'pyrun'):
doctest.DocTestSuite(m).run(result)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment