summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-01-09 08:27:11 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-01-10 09:46:18 -0500
commit474847081a11b0f643df5950f4763ac29a1524b0 (patch)
tree943e1f295b26ba7fcf64d836ca0941b905398b17
parentf08d8a8a1d6f852a9bc04a950ec9f9facaf92f5e (diff)
downloadpython-coveragepy-git-474847081a11b0f643df5950f4763ac29a1524b0.tar.gz
Use the modern way to load modules by file name.
Python 3.10 finally got super-noisy about load_module, which has been deprecated since 3.4! https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module
-rw-r--r--coverage/backward.py12
-rw-r--r--setup.cfg4
-rw-r--r--tests/conftest.py19
3 files changed, 25 insertions, 10 deletions
diff --git a/coverage/backward.py b/coverage/backward.py
index 9d1d78e5..8af3452b 100644
--- a/coverage/backward.py
+++ b/coverage/backward.py
@@ -245,15 +245,17 @@ def import_local_file(modname, modfile=None):
"""
try:
- from importlib.machinery import SourceFileLoader
+ import importlib.util as importlib_util
except ImportError:
- SourceFileLoader = None
+ importlib_util = None
if modfile is None:
modfile = modname + '.py'
- if SourceFileLoader:
- # pylint: disable=no-value-for-parameter, deprecated-method
- mod = SourceFileLoader(modname, modfile).load_module()
+ if importlib_util:
+ spec = importlib_util.spec_from_file_location(modname, modfile)
+ mod = importlib_util.module_from_spec(spec)
+ sys.modules[modname] = mod
+ spec.loader.exec_module(mod)
else:
for suff in imp.get_suffixes(): # pragma: part covered
if suff[0] == '.py':
diff --git a/setup.cfg b/setup.cfg
index 2d015d95..7ba8525a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -2,10 +2,12 @@
addopts = -q -n3 --strict --force-flaky --no-flaky-report -rfe --failed-first
markers =
expensive: too slow to run during "make smoke"
-# How come this warning is suppressed successfully here, but not in conftest.py??
+
+# How come these warnings are suppressed successfully here, but not in conftest.py??
filterwarnings =
ignore:dns.hash module will be removed:DeprecationWarning
ignore:Using or importing the ABCs:DeprecationWarning
+
# xfail tests that pass should fail the test suite
xfail_strict=true
diff --git a/tests/conftest.py b/tests/conftest.py
index 82a6b0f2..10761cdd 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -25,21 +25,32 @@ def set_warnings():
warnings.simplefilter("default")
warnings.simplefilter("once", DeprecationWarning)
- # A warning to suppress:
+ # Warnings to suppress:
+ # How come these warnings are successfully suppressed here, but not in setup.cfg??
+
# setuptools/py33compat.py:54: DeprecationWarning: The value of convert_charrefs will become
# True in 3.5. You are encouraged to set the value explicitly.
# unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)
- # How come this warning is successfully suppressed here, but not in setup.cfg??
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
- message="The value of convert_charrefs will become True in 3.5.",
+ message=r"The value of convert_charrefs will become True in 3.5.",
)
+
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
- message=".* instead of inspect.getfullargspec",
+ message=r".* instead of inspect.getfullargspec",
)
+
+ # <frozen importlib._bootstrap>:681:
+ # ImportWarning: VendorImporter.exec_module() not found; falling back to load_module()
+ warnings.filterwarnings(
+ "ignore",
+ category=ImportWarning,
+ message=r".*exec_module\(\) not found; falling back to load_module\(\)",
+ )
+
if env.PYPY3:
# pypy3 warns about unclosed files a lot.
warnings.filterwarnings("ignore", r".*unclosed file", category=ResourceWarning)