Skip to content

Commit 2e4707d

Browse files
add api to iterate over all marerks of a node
1 parent f38a948 commit 2e4707d

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

_pytest/mark/structures.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,6 @@ def find(self, name):
399399
for mark in self.own_markers:
400400
if mark.name == name:
401401
yield mark
402+
403+
def __iter__(self):
404+
return iter(self.own_markers)

_pytest/nodes.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import absolute_import, division, print_function
22
import os
33

4+
from itertools import chain
5+
46
import six
57
import py
68
import attr
@@ -191,9 +193,20 @@ def find_markers(self, name):
191193
for mark in node._markers.find(name):
192194
yield mark
193195

196+
def iter_markers(self):
197+
"""
198+
iterate over all markers of the node
199+
"""
200+
return chain.from_iterable(x._markers for x in reversed(self.listchain()))
201+
194202
def get_marker(self, name):
195203
""" get a marker object from this node or None if
196-
the node doesn't have a marker with that name. """
204+
the node doesn't have a marker with that name.
205+
206+
..warning::
207+
208+
deprecated
209+
"""
197210
markers = list(self.find_markers(name))
198211
if markers:
199212
return MarkInfo(markers)

doc/en/mark.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ which also serve as documentation.
2626
:ref:`fixtures <fixtures>`.
2727

2828

29+
30+
31+
.. autoclass:: Mark

0 commit comments

Comments
 (0)