Skip to content

Commit

Permalink
Merge pull request pytest-dev#11815 from bluetech/iter_parents-rename
Browse files Browse the repository at this point in the history
nodes: rename `iterparents()` -> `iter_parents()`
  • Loading branch information
bluetech committed Jan 15, 2024
2 parents 3acbdc2 + 707642a commit 6e74601
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion changelog/11801.improvement.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Added the :func:`iterparents() <_pytest.nodes.Node.iterparents>` helper method on nodes.
Added the :func:`iter_parents() <_pytest.nodes.Node.iter_parents>` helper method on nodes.
It is similar to :func:`listchain <_pytest.nodes.Node.listchain>`, but goes from bottom to top, and returns an iterator, not a list.
4 changes: 2 additions & 2 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_scope_package(
) -> Optional[nodes.Node]:
from _pytest.python import Package

for parent in node.iterparents():
for parent in node.iter_parents():
if isinstance(parent, Package) and parent.nodeid == fixturedef.baseid:
return parent
return node.session
Expand Down Expand Up @@ -1775,7 +1775,7 @@ def getfixturedefs(
def _matchfactories(
self, fixturedefs: Iterable[FixtureDef[Any]], node: nodes.Node
) -> Iterator[FixtureDef[Any]]:
parentnodeids = {n.nodeid for n in node.iterparents()}
parentnodeids = {n.nodeid for n in node.iter_parents()}
for fixturedef in fixturedefs:
if fixturedef.baseid in parentnodeids:
yield fixturedef
6 changes: 3 additions & 3 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def setup(self) -> None:
def teardown(self) -> None:
pass

def iterparents(self) -> Iterator["Node"]:
def iter_parents(self) -> Iterator["Node"]:
"""Iterate over all parent collectors starting from and including self
up to the root of the collection tree.
Expand Down Expand Up @@ -318,7 +318,7 @@ def iter_markers_with_node(
:param name: If given, filter the results by the name attribute.
:returns: An iterator of (node, mark) tuples.
"""
for node in self.iterparents():
for node in self.iter_parents():
for mark in node.own_markers:
if name is None or getattr(mark, "name", None) == name:
yield node, mark
Expand Down Expand Up @@ -368,7 +368,7 @@ def getparent(self, cls: Type[_NodeType]) -> Optional[_NodeType]:
:param cls: The node class to search for.
:returns: The node, if found.
"""
for node in self.iterparents():
for node in self.iter_parents():
if isinstance(node, cls):
return node
return None
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def _getobj(self):
def getmodpath(self, stopatmodule: bool = True, includemodule: bool = False) -> str:
"""Return Python path relative to the containing module."""
parts = []
for node in self.iterparents():
for node in self.iter_parents():
name = node.name
if isinstance(node, Module):
name = os.path.splitext(name)[0]
Expand Down

0 comments on commit 6e74601

Please sign in to comment.