diff --git a/src/_pytest/_code/source.py b/src/_pytest/_code/source.py index 379393b10cd..c40c872c7d5 100644 --- a/src/_pytest/_code/source.py +++ b/src/_pytest/_code/source.py @@ -282,7 +282,7 @@ def compile_( # noqa: F811 return s.compile(filename, mode, flags, _genframe=_genframe) -def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int]: +def getfslineno(obj) -> Tuple[Optional[Union[str, py.path.local]], int]: """ Return source location (path, lineno) for the given object. If the source cannot be determined return ("", -1). @@ -305,11 +305,9 @@ def getfslineno(obj) -> Tuple[Optional[Union["Literal['']", py.path.local]], int _, lineno = findsource(obj) except IOError: pass + return fspath, lineno else: - fspath = code.path - lineno = code.firstlineno - assert isinstance(lineno, int) - return fspath, lineno + return code.path, code.firstlineno #