MCPcopy
hub / github.com/pytest-dev/pytest / get_fslocation_from_item

Function get_fslocation_from_item

src/_pytest/nodes.py:472–488  ·  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. * "path": just a path :rtype: A tuple of (str|Path, int) with filename and 0-based line number.

(node: Node)

Source from the content-addressed store, hash-verified

470
471
472def get_fslocation_from_item(node: Node) -> tuple[str | Path, int | None]:
473 """Try to extract the actual location from a node, depending on available attributes:
474
475 * "location": a pair (path, lineno)
476 * "obj": a Python object that the node wraps.
477 * "path": just a path
478
479 :rtype: A tuple of (str|Path, int) with filename and 0-based line number.
480 """
481 # See Item.location.
482 location: tuple[str, int | None, str] | None = getattr(node, "location", None)
483 if location is not None:
484 return location[:2]
485 obj = getattr(node, "obj", None)
486 if obj is not None:
487 return getfslineno(obj)
488 return getattr(node, "path", "unknown location"), -1
489
490
491class Collector(Node, abc.ABC):

Callers 1

warnMethod · 0.85

Calls 1

getfslinenoFunction · 0.90

Tested by

no test coverage detected