Skip to content
1 change: 1 addition & 0 deletions src/_pytest/_code/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def getstatementrange_ast(
pass

# The end might still point to a comment or empty line, correct it.
end = min(end, len(source.lines))
while end:
line = source.lines[end - 1].lstrip()
if line.startswith("#") or not line:
Expand Down