Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
48325b43
Commit
48325b43
authored
Jun 14, 2021
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modernise module loading in test runner using importlib.
parent
3bd321f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
4 deletions
+21
-4
runtests.py
runtests.py
+21
-4
No files found.
runtests.py
View file @
48325b43
...
@@ -543,10 +543,23 @@ def _list_pyregr_data_files(test_directory):
...
@@ -543,10 +543,23 @@ def _list_pyregr_data_files(test_directory):
if is_data_file(filename)]
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):
def import_ext(module_name, file_path=None):
if file_path:
if file_path:
import imp
if sys.version_info >= (3, 5):
return imp.load_dynamic(module_name, file_path)
return import_module_from_file(module_name, file_path)
else:
import imp
return imp.load_dynamic(module_name, file_path)
else:
else:
try:
try:
from importlib import invalidate_caches
from importlib import invalidate_caches
...
@@ -1500,9 +1513,13 @@ class PureDoctestTestCase(unittest.TestCase):
...
@@ -1500,9 +1513,13 @@ class PureDoctestTestCase(unittest.TestCase):
try:
try:
self.setUp()
self.setUp()
import imp
with self.stats.time(self.name, 'py', 'pyimport'):
with self.stats.time(self.name, 'py', 'pyimport'):
m = imp.load_source(loaded_module_name, self.module_path)
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:
try:
with self.stats.time(self.name, 'py', 'pyrun'):
with self.stats.time(self.name, 'py', 'pyrun'):
doctest.DocTestSuite(m).run(result)
doctest.DocTestSuite(m).run(result)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment