Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions src/_pytest/_code/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,27 +283,20 @@ def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int

The line number is 0-based.
"""
from .code import Code

try:
code = Code(obj)
fn = inspect.getsourcefile(obj) or inspect.getfile(obj) # type: ignore[arg-type] # noqa: F821
except TypeError:
return "", -1

assert fn, repr(fn)

fspath = fn and py.path.local(fn) or None
lineno = -1
if fspath:
try:
fn = inspect.getsourcefile(obj) or inspect.getfile(obj)
except TypeError:
return "", -1

fspath = fn and py.path.local(fn) or None
lineno = -1
if fspath:
try:
_, lineno = findsource(obj)
except IOError:
pass
else:
fspath = code.path
lineno = code.firstlineno
assert isinstance(lineno, int)
_, lineno = findsource(obj)
except IOError:
pass
return fspath, lineno


Expand Down