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

Method getparent

src/_pytest/nodes.py:385–395  ·  view source on GitHub ↗

Get the closest parent node (including self) which is an instance of the given class. :param cls: The node class to search for. :returns: The node, if found.

(self, cls: type[_NodeType])

Source from the content-addressed store, hash-verified

383 self.session._setupstate.addfinalizer(fin, self)
384
385 def getparent(self, cls: type[_NodeType]) -> _NodeType | None:
386 """Get the closest parent node (including self) which is an instance of
387 the given class.
388
389 :param cls: The node class to search for.
390 :returns: The node, if found.
391 """
392 for node in self.iter_parents():
393 if isinstance(node, cls):
394 return node
395 return None
396
397 def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback:
398 return excinfo.traceback

Callers 11

moduleMethod · 0.80
clsMethod · 0.80
_genfunctionsMethod · 0.80
get_scope_nodeFunction · 0.80
clsMethod · 0.80
moduleMethod · 0.80
pytest_runtest_setupFunction · 0.80

Calls 1

iter_parentsMethod · 0.95