Skip to content

Commit ff04a92

Browse files
add node iteration apis
TODO: add tests
1 parent 2e4707d commit ff04a92

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

_pytest/nodes.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33

44
from itertools import chain
5-
5+
from operator import itemgetter
66
import six
77
import py
88
import attr
@@ -187,18 +187,34 @@ def find_markers(self, name):
187187
"""find all marks with the given name on the node and its parents
188188
189189
:param str name: name of the marker
190-
:returns: iterator over marks matching the name
190+
:returns: iterator over marks matching the name"""
191+
return map(itemgetter(1), self.find_markers_with_node(name))
192+
193+
def find_markers_with_node(self, name):
194+
"""find all marks with the given name on the node and its parents
195+
196+
:param str name: name of the marker
197+
:returns: iterator over (node, mark) matching the name
191198
"""
192199
for node in reversed(self.listchain()):
193200
for mark in node._markers.find(name):
194-
yield mark
201+
yield node, mark
195202

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

209+
def iter_markers_with_node(self):
210+
"""
211+
iterate over all markers of the node
212+
returns sequence of tuples (node, mark)
213+
"""
214+
for node in reversed(self.listchain()):
215+
for mark in node._markers:
216+
yield node, mark
217+
202218
def get_marker(self, name):
203219
""" get a marker object from this node or None if
204220
the node doesn't have a marker with that name.

0 commit comments

Comments
 (0)