_pytest._code.source module¶
-
class
Source
(*parts, **kwargs)[source]¶ Bases:
object
an immutable object holding a source code fragment, possibly deindenting it.
-
_compilecounter
= 0¶
-
strip
() → _pytest._code.source.Source[source]¶ return new source object with trailing and leading blank lines removed.
-
putaround
(before: str = '', after: str = '', indent: str = ' ') → _pytest._code.source.Source[source]¶ return a copy of the source object with ‘before’ and ‘after’ wrapped around it.
-
indent
(indent: str = ' ') → _pytest._code.source.Source[source]¶ return a copy of the source object with all lines indented by the given indent-string.
-
getstatement
(lineno: int) → _pytest._code.source.Source[source]¶ return Source statement which contains the given linenumber (counted from 0).
-
getstatementrange
(lineno: int) → Tuple[int, int][source]¶ return (start, end) tuple which spans the minimal statement region which containing the given lineno.
-
deindent
() → _pytest._code.source.Source[source]¶ return a new source object deindented.
-
isparseable
(deindent: bool = True) → bool[source]¶ return True if source is parseable, heuristically deindenting it by default.
-
compile
(filename: Optional[str] = None, mode: str = 'exec', flag: int = 0, dont_inherit: int = 0, _genframe: Optional[frame] = None) → Union[code, _ast.AST][source]¶ return compiled code object. if filename is None invent an artificial filename which displays the source/line position of the caller frame.
-
-
compile_
(source: Union[str, bytes, _ast.mod, _ast.AST], filename: Optional[str] = None, mode: str = 'exec', flags: int = 0, dont_inherit: int = 0) → Union[code, _ast.AST][source]¶ compile the given source to a raw code object, and maintain an internal cache which allows later retrieval of the source code for the code object and any recursively created code objects.
-
getfslineno
(obj: Any) → Tuple[Union[str, py._path.local.LocalPath], int][source]¶ Return source location (path, lineno) for the given object. If the source cannot be determined return (“”, -1).
The line number is 0-based.
-
findsource
(obj) → Tuple[Optional[_pytest._code.source.Source], int][source]¶
-
getsource
(obj, **kwargs) → _pytest._code.source.Source[source]¶