Skip to content

Commit c1482d5

Browse files
authored
Merge pull request #27109 from QuLogic/testing-importlib
TST: Use importlib for subprocess tests
2 parents 75c1fd3 + 9c6db66 commit c1482d5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/matplotlib/testing/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,16 @@ def subprocess_run_helper(func, *args, timeout, extra_env=None):
122122
"""
123123
target = func.__name__
124124
module = func.__module__
125+
file = func.__code__.co_filename
125126
proc = subprocess_run_for_testing(
126127
[
127128
sys.executable,
128129
"-c",
129-
f"from {module} import {target}; {target}()",
130+
f"import importlib.util;"
131+
f"_spec = importlib.util.spec_from_file_location({module!r}, {file!r});"
132+
f"_module = importlib.util.module_from_spec(_spec);"
133+
f"_spec.loader.exec_module(_module);"
134+
f"_module.{target}()",
130135
*args
131136
],
132137
env={**os.environ, "SOURCE_DATE_EPOCH": "0", **(extra_env or {})},

0 commit comments

Comments
 (0)