From cb713c670d518b5cf7979eb8e07c02e6f29053fb Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 19 Oct 2022 16:58:16 -0400 Subject: [PATCH] _pytest._py.path: importlib mode always available --- src/_pytest/_py/path.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/_pytest/_py/path.py b/src/_pytest/_py/path.py index f51e574cef..3fc0d694be 100644 --- a/src/_pytest/_py/path.py +++ b/src/_pytest/_py/path.py @@ -1,8 +1,11 @@ """ local path implementation. """ +from __future__ import annotations + import atexit import fnmatch +import importlib.util import io import os import posixpath @@ -440,11 +443,6 @@ def map_as_list(func, iter): return list(map(func, iter)) -ALLOW_IMPORTLIB_MODE = sys.version_info > (3, 5) -if ALLOW_IMPORTLIB_MODE: - import importlib - - class Stat: def __getattr__(self, name): return getattr(self._osstatresult, "st_" + name) @@ -1110,8 +1108,6 @@ def pyimport(self, modname=None, ensuresyspath=True): if ensuresyspath == "importlib": if modname is None: modname = self.purebasename - if not ALLOW_IMPORTLIB_MODE: - raise ImportError("Can't use importlib due to old version of Python") spec = importlib.util.spec_from_file_location(modname, str(self)) if spec is None: raise ImportError(