MCPcopy Create free account
hub / github.com/pytest-dev/pytest / ReprEntry

Class ReprEntry

src/_pytest/_code/code.py:1074–1150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1072
1073@attr.s(eq=False, auto_attribs=True)
1074class ReprEntry(TerminalRepr):
1075 lines: Sequence[str]
1076 reprfuncargs: Optional["ReprFuncArgs"]
1077 reprlocals: Optional["ReprLocals"]
1078 reprfileloc: Optional["ReprFileLocation"]
1079 style: "_TracebackStyle"
1080
1081 def _write_entry_lines(self, tw: TerminalWriter) -> None:
1082 """Write the source code portions of a list of traceback entries with syntax highlighting.
1083
1084 Usually entries are lines like these:
1085
1086 " x = 1"
1087 "> assert x == 2"
1088 "E assert 1 == 2"
1089
1090 This function takes care of rendering the "source" portions of it (the lines without
1091 the "E" prefix) using syntax highlighting, taking care to not highlighting the ">"
1092 character, as doing so might break line continuations.
1093 """
1094
1095 if not self.lines:
1096 return
1097
1098 # separate indents and source lines that are not failures: we want to
1099 # highlight the code but not the indentation, which may contain markers
1100 # such as "> assert 0"
1101 fail_marker = f"{FormattedExcinfo.fail_marker} "
1102 indent_size = len(fail_marker)
1103 indents: List[str] = []
1104 source_lines: List[str] = []
1105 failure_lines: List[str] = []
1106 for index, line in enumerate(self.lines):
1107 is_failure_line = line.startswith(fail_marker)
1108 if is_failure_line:
1109 # from this point on all lines are considered part of the failure
1110 failure_lines.extend(self.lines[index:])
1111 break
1112 else:
1113 if self.style == "value":
1114 source_lines.append(line)
1115 else:
1116 indents.append(line[:indent_size])
1117 source_lines.append(line[indent_size:])
1118
1119 tw._write_source(source_lines, indents)
1120
1121 # failure lines are always completely red and bold
1122 for line in failure_lines:
1123 tw.line(line, bold=True, red=True)
1124
1125 def toterminal(self, tw: TerminalWriter) -> None:
1126 if self.style == "short":
1127 assert self.reprfileloc is not None
1128 self.reprfileloc.toterminal(tw)
1129 self._write_entry_lines(tw)
1130 if self.reprlocals:
1131 self.reprlocals.toterminal(tw, indent=" " * 8)

Callers 2

deserialize_repr_entryFunction · 0.90
repr_traceback_entryMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected