Skip to content

Commit

Permalink
add node iteration apis
Browse files Browse the repository at this point in the history
TODO: add tests
  • Loading branch information
RonnyPfannschmidt committed Mar 26, 2018
1 parent 2e4707d commit ff04a92
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions _pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

from itertools import chain

from operator import itemgetter
import six
import py
import attr
Expand Down Expand Up @@ -187,18 +187,34 @@ def find_markers(self, name):
"""find all marks with the given name on the node and its parents
:param str name: name of the marker
:returns: iterator over marks matching the name
:returns: iterator over marks matching the name"""
return map(itemgetter(1), self.find_markers_with_node(name))

def find_markers_with_node(self, name):
"""find all marks with the given name on the node and its parents
:param str name: name of the marker
:returns: iterator over (node, mark) matching the name
"""
for node in reversed(self.listchain()):
for mark in node._markers.find(name):
yield mark
yield node, mark

def iter_markers(self):
"""
iterate over all markers of the node
"""
return chain.from_iterable(x._markers for x in reversed(self.listchain()))

def iter_markers_with_node(self):
"""
iterate over all markers of the node
returns sequence of tuples (node, mark)
"""
for node in reversed(self.listchain()):
for mark in node._markers:
yield node, mark

def get_marker(self, name):
""" get a marker object from this node or None if
the node doesn't have a marker with that name.
Expand Down

0 comments on commit ff04a92

Please sign in to comment.