_pytest._py.path: importlib mode always available
This commit is contained in:
parent
eebbfc65c9
commit
63c4d45c59
|
@ -1,8 +1,11 @@
|
||||||
"""
|
"""
|
||||||
local path implementation.
|
local path implementation.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import importlib.util
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
|
@ -440,11 +443,6 @@ def map_as_list(func, iter):
|
||||||
return list(map(func, iter))
|
return list(map(func, iter))
|
||||||
|
|
||||||
|
|
||||||
ALLOW_IMPORTLIB_MODE = sys.version_info > (3, 5)
|
|
||||||
if ALLOW_IMPORTLIB_MODE:
|
|
||||||
import importlib
|
|
||||||
|
|
||||||
|
|
||||||
class Stat:
|
class Stat:
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self._osstatresult, "st_" + name)
|
return getattr(self._osstatresult, "st_" + name)
|
||||||
|
@ -1110,8 +1108,6 @@ class LocalPath(FSBase):
|
||||||
if ensuresyspath == "importlib":
|
if ensuresyspath == "importlib":
|
||||||
if modname is None:
|
if modname is None:
|
||||||
modname = self.purebasename
|
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))
|
spec = importlib.util.spec_from_file_location(modname, str(self))
|
||||||
if spec is None:
|
if spec is None:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
|
|
Loading…
Reference in New Issue