aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest/py3/_pytest/compat.py
diff options
context:
space:
mode:
authorarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-02-14 00:49:36 +0300
committerarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-02-14 00:49:36 +0300
commit82cfd1b7cab2d843cdf5467d9737f72597a493bd (patch)
tree1dfdcfe81a1a6b193ceacc2a828c521b657a339b /contrib/python/pytest/py3/_pytest/compat.py
parent3df7211d3e3691f8e33b0a1fb1764fe810d59302 (diff)
downloadydb-82cfd1b7cab2d843cdf5467d9737f72597a493bd.tar.gz
intermediate changes
ref:68b1302de4b5da30b6bdf02193f7a2604d8b5cf8
Diffstat (limited to 'contrib/python/pytest/py3/_pytest/compat.py')
-rw-r--r--contrib/python/pytest/py3/_pytest/compat.py39
1 files changed, 28 insertions, 11 deletions
diff --git a/contrib/python/pytest/py3/_pytest/compat.py b/contrib/python/pytest/py3/_pytest/compat.py
index c23cc962ce..25894d344d 100644
--- a/contrib/python/pytest/py3/_pytest/compat.py
+++ b/contrib/python/pytest/py3/_pytest/compat.py
@@ -2,7 +2,7 @@
import enum
import functools
import inspect
-import re
+import os
import sys
from contextlib import contextmanager
from inspect import Parameter
@@ -18,9 +18,7 @@ from typing import TypeVar
from typing import Union
import attr
-
-from _pytest.outcomes import fail
-from _pytest.outcomes import TEST_OUTCOME
+import py
if TYPE_CHECKING:
from typing import NoReturn
@@ -30,6 +28,19 @@ if TYPE_CHECKING:
_T = TypeVar("_T")
_S = TypeVar("_S")
+#: constant to prepare valuing pylib path replacements/lazy proxies later on
+# intended for removal in pytest 8.0 or 9.0
+
+# fmt: off
+# intentional space to create a fake difference for the verification
+LEGACY_PATH = py.path. local
+# fmt: on
+
+
+def legacy_path(path: Union[str, "os.PathLike[str]"]) -> LEGACY_PATH:
+ """Internal wrapper to prepare lazy proxies for legacy_path instances"""
+ return LEGACY_PATH(path)
+
# fmt: off
# Singleton type for NOTSET, as described in:
@@ -49,10 +60,6 @@ def _format_args(func: Callable[..., Any]) -> str:
return str(signature(func))
-# The type of re.compile objects is not exposed in Python.
-REGEX_TYPE = type(re.compile(""))
-
-
def is_generator(func: object) -> bool:
genfunc = inspect.isgeneratorfunction(func)
return genfunc and not iscoroutinefunction(func)
@@ -142,8 +149,11 @@ def getfuncargnames(
try:
parameters = signature(function).parameters
except (ValueError, TypeError) as e:
+ from _pytest.outcomes import fail
+
fail(
- f"Could not determine arguments of {function!r}: {e}", pytrace=False,
+ f"Could not determine arguments of {function!r}: {e}",
+ pytrace=False,
)
arg_names = tuple(
@@ -162,7 +172,12 @@ def getfuncargnames(
# it's passed as an unbound method or function, remove the first
# parameter name.
if is_method or (
- cls and not isinstance(cls.__dict__.get(name, None), staticmethod)
+ # Not using `getattr` because we don't want to resolve the staticmethod.
+ # Not using `cls.__dict__` because we want to check the entire MRO.
+ cls
+ and not isinstance(
+ inspect.getattr_static(cls, name, default=None), staticmethod
+ )
):
arg_names = arg_names[1:]
# Remove any names that will be replaced with mocks.
@@ -308,6 +323,8 @@ def safe_getattr(object: Any, name: str, default: Any) -> Any:
are derived from BaseException instead of Exception (for more details
check #2707).
"""
+ from _pytest.outcomes import TEST_OUTCOME
+
try:
return getattr(object, name, default)
except TEST_OUTCOME:
@@ -397,4 +414,4 @@ else:
#
# This also work for Enums (if you use `is` to compare) and Literals.
def assert_never(value: "NoReturn") -> "NoReturn":
- assert False, "Unhandled value: {} ({})".format(value, type(value).__name__)
+ assert False, f"Unhandled value: {value} ({type(value).__name__})"