reports: use attr.asdict with serialize_repr_{crash,traceback} (#6732)
* Turn ReprTraceback into attrs class * Use attr.asdict with serialize_repr_{crash,traceback} * Turn ReprFileLocation into attrs class, convert py.path.local
This commit is contained in:
parent
4b70ba2c21
commit
9631b3c166
|
@ -975,18 +975,13 @@ class ReprExceptionInfo(ExceptionRepr):
|
||||||
super().toterminal(tw)
|
super().toterminal(tw)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s
|
||||||
class ReprTraceback(TerminalRepr):
|
class ReprTraceback(TerminalRepr):
|
||||||
entrysep = "_ "
|
reprentries = attr.ib(type=Sequence[Union["ReprEntry", "ReprEntryNative"]])
|
||||||
|
extraline = attr.ib(type=Optional[str])
|
||||||
|
style = attr.ib(type="_TracebackStyle")
|
||||||
|
|
||||||
def __init__(
|
entrysep = "_ "
|
||||||
self,
|
|
||||||
reprentries: Sequence[Union["ReprEntry", "ReprEntryNative"]],
|
|
||||||
extraline: Optional[str],
|
|
||||||
style: "_TracebackStyle",
|
|
||||||
) -> None:
|
|
||||||
self.reprentries = reprentries
|
|
||||||
self.extraline = extraline
|
|
||||||
self.style = style
|
|
||||||
|
|
||||||
def toterminal(self, tw: TerminalWriter) -> None:
|
def toterminal(self, tw: TerminalWriter) -> None:
|
||||||
# the entries might have different styles
|
# the entries might have different styles
|
||||||
|
@ -1105,11 +1100,11 @@ class ReprEntry(TerminalRepr):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s
|
||||||
class ReprFileLocation(TerminalRepr):
|
class ReprFileLocation(TerminalRepr):
|
||||||
def __init__(self, path, lineno: int, message: str) -> None:
|
path = attr.ib(type=str, converter=str)
|
||||||
self.path = str(path)
|
lineno = attr.ib(type=int)
|
||||||
self.lineno = lineno
|
message = attr.ib(type=str)
|
||||||
self.message = message
|
|
||||||
|
|
||||||
def toterminal(self, tw: TerminalWriter) -> None:
|
def toterminal(self, tw: TerminalWriter) -> None:
|
||||||
# filename and lineno output for each entry,
|
# filename and lineno output for each entry,
|
||||||
|
|
|
@ -6,6 +6,7 @@ from typing import Optional
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
|
import attr
|
||||||
import py
|
import py
|
||||||
|
|
||||||
from _pytest._code.code import ExceptionChainRepr
|
from _pytest._code.code import ExceptionChainRepr
|
||||||
|
@ -375,8 +376,8 @@ def _report_to_json(report):
|
||||||
entry_data["data"][key] = value.__dict__.copy()
|
entry_data["data"][key] = value.__dict__.copy()
|
||||||
return entry_data
|
return entry_data
|
||||||
|
|
||||||
def serialize_repr_traceback(reprtraceback):
|
def serialize_repr_traceback(reprtraceback: ReprTraceback):
|
||||||
result = reprtraceback.__dict__.copy()
|
result = attr.asdict(reprtraceback)
|
||||||
result["reprentries"] = [
|
result["reprentries"] = [
|
||||||
serialize_repr_entry(x) for x in reprtraceback.reprentries
|
serialize_repr_entry(x) for x in reprtraceback.reprentries
|
||||||
]
|
]
|
||||||
|
@ -384,7 +385,7 @@ def _report_to_json(report):
|
||||||
|
|
||||||
def serialize_repr_crash(reprcrash: Optional[ReprFileLocation]):
|
def serialize_repr_crash(reprcrash: Optional[ReprFileLocation]):
|
||||||
if reprcrash is not None:
|
if reprcrash is not None:
|
||||||
return reprcrash.__dict__.copy()
|
return attr.asdict(reprcrash)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue