Skip to content

Commit 3340160

Browse files
authored
Merge pull request #219 from mgorny/shutil-imp
pytest-shutil: Replace deprecated imp module
2 parents 2b390dc + bbb9e5c commit 3340160

File tree

1 file changed

+5
-2
lines changed
  • pytest-shutil/pytest_shutil

1 file changed

+5
-2
lines changed

pytest-shutil/pytest_shutil/run.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
import sys
55
import os
6-
import imp
6+
import importlib.util
77
import logging
88
from functools import update_wrapper
99
import inspect
@@ -112,7 +112,10 @@ def run_module_as_main(module, argv=[]):
112112
filename = os.path.splitext(filename)[0] + ".py"
113113

114114
with patch("sys.argv", new=argv):
115-
imp.load_source('__main__', os.path.join(where, filename))
115+
spec = importlib.util.spec_from_file_location(
116+
"__main__", os.path.join(where, filename))
117+
module = importlib.util.module_from_spec(spec)
118+
spec.loader.exec_module(module)
116119

117120

118121
def _evaluate_fn_source(src, *args, **kwargs):

0 commit comments

Comments
 (0)