Skip to content

Commit

Permalink
FormattedExcinfo.get_source: Avoid a crash when source.lines == 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodiologist committed Mar 26, 2023
1 parent a3b3906 commit a3424b4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,11 @@ def get_source(
) -> List[str]:
"""Return formatted and marked up source lines."""
lines = []
if source is None or line_index >= len(source.lines):
source = Source("???")
line_index = 0
if line_index < 0:
line_index += len(source)
if source is None or line_index >= len(source.lines) or line_index < 0:
source = Source("???")
line_index = 0
space_prefix = " "
if short:
lines.append(space_prefix + source.lines[line_index].strip())
Expand Down

0 comments on commit a3424b4

Please sign in to comment.