Skip to content

Commit c8317a7

Browse files
committed
WIP: fix
1 parent abbe15d commit c8317a7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/_pytest/_code/code.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,14 @@ def getsource(self, astcache=None) -> Optional["Source"]:
244244
astnode = astcache.get(key, None)
245245
start = self.getfirstlinesource()
246246
try:
247-
astnode, _, end = getstatementrange_ast(
247+
astnode, ast_start, end = getstatementrange_ast(
248248
self.lineno, source, astnode=astnode
249249
)
250250
except SyntaxError:
251251
end = self.lineno + 1
252252
else:
253+
if ast_start - 1 < start:
254+
start = ast_start
253255
if key is not None:
254256
astcache[key] = astnode
255257
return source[start:end]

src/_pytest/_code/source.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ def get_statement_startend2(lineno: int, node: ast.AST) -> Tuple[int, Optional[i
357357
# AST's line numbers start indexing at 1
358358
values = [] # type: List[int]
359359
for x in ast.walk(node):
360+
if isinstance(x, (ast.FunctionDef)):
361+
values.extend(deco.lineno - 1 for deco in x.decorator_list)
360362
if isinstance(x, (ast.stmt, ast.ExceptHandler)):
361363
values.append(x.lineno - 1)
362364
for name in ("finalbody", "orelse"):

0 commit comments

Comments
 (0)