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

Method get_source

src/_pytest/_code/code.py:731–757  ·  view source on GitHub ↗

Return formatted and marked up source lines.

(
        self,
        source: Optional["Source"],
        line_index: int = -1,
        excinfo: Optional[ExceptionInfo[BaseException]] = None,
        short: bool = False,
    )

Source from the content-addressed store, hash-verified

729 return None
730
731 def get_source(
732 self,
733 source: Optional["Source"],
734 line_index: int = -1,
735 excinfo: Optional[ExceptionInfo[BaseException]] = None,
736 short: bool = False,
737 ) -> List[str]:
738 """Return formatted and marked up source lines."""
739 lines = []
740 if source is None or line_index >= len(source.lines):
741 source = Source("???")
742 line_index = 0
743 if line_index < 0:
744 line_index += len(source)
745 space_prefix = " "
746 if short:
747 lines.append(space_prefix + source.lines[line_index].strip())
748 else:
749 for line in source.lines[:line_index]:
750 lines.append(space_prefix + line)
751 lines.append(self.flow_marker + " " + source.lines[line_index])
752 for line in source.lines[line_index + 1 :]:
753 lines.append(space_prefix + line)
754 if excinfo is not None:
755 indent = 4 if short else self._getindent(source)
756 lines.extend(self.get_exconly(excinfo, indent=indent, markall=True))
757 return lines
758
759 def get_exconly(
760 self,

Callers 3

repr_traceback_entryMethod · 0.95
test_repr_sourceMethod · 0.95

Calls 5

_getindentMethod · 0.95
get_exconlyMethod · 0.95
SourceClass · 0.90
appendMethod · 0.80
stripMethod · 0.80

Tested by 2

test_repr_sourceMethod · 0.76