Skip to content

Commit

Permalink
WIP: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Mar 10, 2020
1 parent 006baa3 commit 94770e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/_pytest/_code/code.py
Expand Up @@ -244,12 +244,14 @@ def getsource(self, astcache=None) -> Optional["Source"]:
astnode = astcache.get(key, None)
start = self.getfirstlinesource()
try:
astnode, _, end = getstatementrange_ast(
astnode, ast_start, end = getstatementrange_ast(
self.lineno, source, astnode=astnode
)
except SyntaxError:
end = self.lineno + 1
else:
if ast_start - 1 < start:
start = ast_start
if key is not None:
astcache[key] = astnode
return source[start:end]
Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/_code/source.py
Expand Up @@ -352,6 +352,8 @@ def get_statement_startend2(lineno: int, node: ast.AST) -> Tuple[int, Optional[i
# AST's line numbers start indexing at 1
values = [] # type: List[int]
for x in ast.walk(node):
if isinstance(x, (ast.FunctionDef)):
values.extend(deco.lineno - 1 for deco in x.decorator_list)
if isinstance(x, (ast.stmt, ast.ExceptHandler)):
values.append(x.lineno - 1)
for name in ("finalbody", "orelse"):
Expand Down

0 comments on commit 94770e8

Please sign in to comment.