MCPcopy Create free account
hub / github.com/pytest-dev/pytest / get_fslocation_from_item

Function get_fslocation_from_item

src/_pytest/nodes.py:498–514  ·  view source on GitHub ↗

Try to extract the actual location from a node, depending on available attributes: * "location": a pair (path, lineno) * "obj": a Python object that the node wraps. * "fspath": just a path :rtype: A tuple of (str|Path, int) with filename and line number.

(node: "Node")

Source from the content-addressed store, hash-verified

496
497
498def get_fslocation_from_item(node: "Node") -> Tuple[Union[str, Path], Optional[int]]:
499 """Try to extract the actual location from a node, depending on available attributes:
500
501 * "location": a pair (path, lineno)
502 * "obj": a Python object that the node wraps.
503 * "fspath": just a path
504
505 :rtype: A tuple of (str|Path, int) with filename and line number.
506 """
507 # See Item.location.
508 location: Optional[Tuple[str, Optional[int], str]] = getattr(node, "location", None)
509 if location is not None:
510 return location[:2]
511 obj = getattr(node, "obj", None)
512 if obj is not None:
513 return getfslineno(obj)
514 return getattr(node, "fspath", "unknown location"), -1
515
516
517class Collector(Node):

Callers 1

warnMethod · 0.85

Calls 1

getfslinenoFunction · 0.90

Tested by

no test coverage detected