aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest/py3/_pytest/reports.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/reports.py
parent3df7211d3e3691f8e33b0a1fb1764fe810d59302 (diff)
downloadydb-82cfd1b7cab2d843cdf5467d9737f72597a493bd.tar.gz
intermediate changes
ref:68b1302de4b5da30b6bdf02193f7a2604d8b5cf8
Diffstat (limited to 'contrib/python/pytest/py3/_pytest/reports.py')
-rw-r--r--contrib/python/pytest/py3/_pytest/reports.py72
1 files changed, 49 insertions, 23 deletions
diff --git a/contrib/python/pytest/py3/_pytest/reports.py b/contrib/python/pytest/py3/_pytest/reports.py
index 58f12517c5b..a68e68bc526 100644
--- a/contrib/python/pytest/py3/_pytest/reports.py
+++ b/contrib/python/pytest/py3/_pytest/reports.py
@@ -1,5 +1,5 @@
+import os
from io import StringIO
-from pathlib import Path
from pprint import pprint
from typing import Any
from typing import cast
@@ -15,7 +15,6 @@ from typing import TypeVar
from typing import Union
import attr
-import py
from _pytest._code.code import ExceptionChainRepr
from _pytest._code.code import ExceptionInfo
@@ -65,6 +64,7 @@ class BaseReport:
]
sections: List[Tuple[str, str]]
nodeid: str
+ outcome: "Literal['passed', 'failed', 'skipped']"
def __init__(self, **kw: Any) -> None:
self.__dict__.update(kw)
@@ -76,7 +76,9 @@ class BaseReport:
def toterminal(self, out: TerminalWriter) -> None:
if hasattr(self, "node"):
- out.line(getworkerinfoline(self.node))
+ worker_info = getworkerinfoline(self.node)
+ if worker_info:
+ out.line(worker_info)
longrepr = self.longrepr
if longrepr is None:
@@ -141,12 +143,24 @@ class BaseReport:
content for (prefix, content) in self.get_sections("Captured stderr")
)
- passed = property(lambda x: x.outcome == "passed")
- failed = property(lambda x: x.outcome == "failed")
- skipped = property(lambda x: x.outcome == "skipped")
+ @property
+ def passed(self) -> bool:
+ """Whether the outcome is passed."""
+ return self.outcome == "passed"
+
+ @property
+ def failed(self) -> bool:
+ """Whether the outcome is failed."""
+ return self.outcome == "failed"
+
+ @property
+ def skipped(self) -> bool:
+ """Whether the outcome is skipped."""
+ return self.outcome == "skipped"
@property
def fspath(self) -> str:
+ """The path portion of the reported node, as a string."""
return self.nodeid.split("::")[0]
@property
@@ -229,7 +243,10 @@ def _report_unserialization_failure(
@final
class TestReport(BaseReport):
"""Basic test report object (also used for setup and teardown calls if
- they fail)."""
+ they fail).
+
+ Reports can contain arbitrary extra attributes.
+ """
__test__ = False
@@ -273,10 +290,10 @@ class TestReport(BaseReport):
#: defined properties of the test.
self.user_properties = list(user_properties or [])
- #: List of pairs ``(str, str)`` of extra information which needs to
- #: marshallable. Used by pytest to add captured text
- #: from ``stdout`` and ``stderr``, but may be used by other plugins
- #: to add arbitrary information to reports.
+ #: Tuples of str ``(heading, content)`` with extra information
+ #: for the test report. Used by pytest to add text captured
+ #: from ``stdout``, ``stderr``, and intercepted logging events. May
+ #: be used by other plugins to add arbitrary information to reports.
self.sections = list(sections)
#: Time it took to run just the test.
@@ -307,7 +324,7 @@ class TestReport(BaseReport):
Tuple[str, int, str],
str,
TerminalRepr,
- ] = (None)
+ ] = None
else:
if not isinstance(excinfo, ExceptionInfo):
outcome = "failed"
@@ -315,7 +332,12 @@ class TestReport(BaseReport):
elif isinstance(excinfo.value, skip.Exception):
outcome = "skipped"
r = excinfo._getreprcrash()
- longrepr = (str(r.path), r.lineno, r.message)
+ if excinfo.value._use_item_location:
+ path, line = item.reportinfo()[:2]
+ assert line is not None
+ longrepr = os.fspath(path), line + 1, r.message
+ else:
+ longrepr = (str(r.path), r.lineno, r.message)
else:
outcome = "failed"
if call.when == "call":
@@ -341,15 +363,20 @@ class TestReport(BaseReport):
@final
class CollectReport(BaseReport):
- """Collection report object."""
+ """Collection report object.
+
+ Reports can contain arbitrary extra attributes.
+ """
when = "collect"
def __init__(
self,
nodeid: str,
- outcome: "Literal['passed', 'skipped', 'failed']",
- longrepr,
+ outcome: "Literal['passed', 'failed', 'skipped']",
+ longrepr: Union[
+ None, ExceptionInfo[BaseException], Tuple[str, int, str], str, TerminalRepr
+ ],
result: Optional[List[Union[Item, Collector]]],
sections: Iterable[Tuple[str, str]] = (),
**extra,
@@ -366,11 +393,10 @@ class CollectReport(BaseReport):
#: The collected items and collection nodes.
self.result = result or []
- #: List of pairs ``(str, str)`` of extra information which needs to
- #: marshallable.
- # Used by pytest to add captured text : from ``stdout`` and ``stderr``,
- # but may be used by other plugins : to add arbitrary information to
- # reports.
+ #: Tuples of str ``(heading, content)`` with extra information
+ #: for the test report. Used by pytest to add text captured
+ #: from ``stdout``, ``stderr``, and intercepted logging events. May
+ #: be used by other plugins to add arbitrary information to reports.
self.sections = list(sections)
self.__dict__.update(extra)
@@ -484,8 +510,8 @@ def _report_to_json(report: BaseReport) -> Dict[str, Any]:
else:
d["longrepr"] = report.longrepr
for name in d:
- if isinstance(d[name], (py.path.local, Path)):
- d[name] = str(d[name])
+ if isinstance(d[name], os.PathLike):
+ d[name] = os.fspath(d[name])
elif name == "result":
d[name] = None # for now
return d