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

Method repr_traceback_entry

src/_pytest/_code/code.py:802–836  ·  view source on GitHub ↗
(
        self,
        entry: TracebackEntry,
        excinfo: Optional[ExceptionInfo[BaseException]] = None,
    )

Source from the content-addressed store, hash-verified

800 return None
801
802 def repr_traceback_entry(
803 self,
804 entry: TracebackEntry,
805 excinfo: Optional[ExceptionInfo[BaseException]] = None,
806 ) -> "ReprEntry":
807 lines: List[str] = []
808 style = entry._repr_style if entry._repr_style is not None else self.style
809 if style in ("short", "long"):
810 source = self._getentrysource(entry)
811 if source is None:
812 source = Source("???")
813 line_index = 0
814 else:
815 line_index = entry.lineno - entry.getfirstlinesource()
816 short = style == "short"
817 reprargs = self.repr_args(entry) if not short else None
818 s = self.get_source(source, line_index, excinfo, short=short)
819 lines.extend(s)
820 if short:
821 message = "in %s" % (entry.name)
822 else:
823 message = excinfo and excinfo.typename or ""
824 entry_path = entry.path
825 path = self._makepath(entry_path)
826 reprfileloc = ReprFileLocation(path, entry.lineno + 1, message)
827 localsrepr = self.repr_locals(entry.locals)
828 return ReprEntry(lines, reprargs, localsrepr, reprfileloc, style)
829 elif style == "value":
830 if excinfo:
831 lines.extend(str(excinfo.value).split("\n"))
832 return ReprEntry(lines, None, None, None, style)
833 else:
834 if excinfo:
835 lines.extend(self.get_exconly(excinfo, indent=4))
836 return ReprEntry(lines, None, None, None, style)
837
838 def _makepath(self, path: Union[Path, str]) -> str:
839 if not self.abspath and isinstance(path, Path):

Calls 10

_getentrysourceMethod · 0.95
repr_argsMethod · 0.95
get_sourceMethod · 0.95
_makepathMethod · 0.95
repr_localsMethod · 0.95
get_exconlyMethod · 0.95
SourceClass · 0.90
ReprFileLocationClass · 0.85
ReprEntryClass · 0.85
getfirstlinesourceMethod · 0.80