We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
IndexError
getstatementrange_ast
1 parent 68524d4 commit 0909655Copy full SHA for 0909655
changelog/11953.bugfix.rst
@@ -0,0 +1 @@
1
+Fix an ``IndexError`` crash raising from ``getstatementrange_ast``.
src/_pytest/_code/source.py
@@ -196,7 +196,9 @@ def getstatementrange_ast(
196
# by using the BlockFinder helper used which inspect.getsource() uses itself.
197
block_finder = inspect.BlockFinder()
198
# If we start with an indented line, put blockfinder to "started" mode.
199
- block_finder.started = source.lines[start][0].isspace()
+ block_finder.started = (
200
+ bool(source.lines[start]) and source.lines[start][0].isspace()
201
+ )
202
it = ((x + "\n") for x in source.lines[start:end])
203
try:
204
for tok in tokenize.generate_tokens(lambda: next(it)):
0 commit comments