From 8805036fd8596750caa588853707346235ae6bdd Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Mon, 26 Mar 2018 17:53:04 +0200 Subject: [PATCH] add node iteration apis TODO: add tests --- _pytest/nodes.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/_pytest/nodes.py b/_pytest/nodes.py index 5238e345d..215da0825 100644 --- a/_pytest/nodes.py +++ b/_pytest/nodes.py @@ -2,7 +2,7 @@ from __future__ import absolute_import, division, print_function import os from itertools import chain - +from operator import itemgetter import six import py import attr @@ -187,11 +187,18 @@ class Node(object): """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): """ @@ -199,6 +206,15 @@ class Node(object): """ 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.