summaryrefslogtreecommitdiff
path: root/_pytest/main.py
diff options
context:
space:
mode:
authorholger krekel <holger@merlinux.eu>2012-10-18 13:52:32 +0200
committerholger krekel <holger@merlinux.eu>2012-10-18 13:52:32 +0200
commit7d747a1cde5dbe825d77a24ea68e0889aea45fa0 (patch)
tree217a31661305752dbdcf08954b7df9717813e3c3 /_pytest/main.py
parentdbaedbacde12cfb7c326101c693377a6851382d7 (diff)
downloadpytest-7d747a1cde5dbe825d77a24ea68e0889aea45fa0.tar.gz
remove .markers attribute which was added in development and after 2.2.4
so never released. Rather extend keywords to also exist on nodes. Assigning to node.keywords will make the value appear on all subchildren's keywords.
Diffstat (limited to '_pytest/main.py')
-rw-r--r--_pytest/main.py53
1 files changed, 32 insertions, 21 deletions
diff --git a/_pytest/main.py b/_pytest/main.py
index 565652e81..4f310d756 100644
--- a/_pytest/main.py
+++ b/_pytest/main.py
@@ -4,6 +4,10 @@ import py
import pytest, _pytest
import inspect
import os, sys, imp
+try:
+ from collections import MutableMapping as MappingMixin
+except ImportError:
+ from UserDict import DictMixin as MappingMixin
from _pytest.mark import MarkInfo
@@ -160,6 +164,32 @@ def compatproperty(name):
return property(fget)
+class NodeKeywords(MappingMixin):
+ def __init__(self, node):
+ parent = node.parent
+ bases = parent and (parent.keywords._markers,) or ()
+ self._markers = type("dynmarker", bases, {node.name: True})
+
+ def __getitem__(self, key):
+ try:
+ return getattr(self._markers, key)
+ except AttributeError:
+ raise KeyError(key)
+
+ def __setitem__(self, key, value):
+ setattr(self._markers, key, value)
+
+ def __delitem__(self, key):
+ delattr(self._markers, key)
+
+ def __iter__(self):
+ return iter(self.keys())
+
+ def __len__(self):
+ return len(self.keys())
+
+ def keys(self):
+ return dir(self._markers)
class Node(object):
""" base class for Collector and Item the test collection tree.
@@ -184,30 +214,11 @@ class Node(object):
#: fspath sensitive hook proxy used to call pytest hooks
self.ihook = self.session.gethookproxy(self.fspath)
- bases = parent and (parent.markers,) or ()
-
- #: marker class with markers from all scopes accessible as attributes
- self.markers = type("dynmarker", bases, {self.name: True})
+ #: keywords/markers collected from all scopes
+ self.keywords = NodeKeywords(self)
#self.extrainit()
- @property
- def keywords(self):
- """ dictionary of Keywords / markers on this node. """
- return vars(self.markers)
-
- def applymarker(self, marker):
- """ Apply a marker to this item. This method is
- useful if you have several parametrized function
- and want to mark a single one of them.
-
- :arg marker: a :py:class:`_pytest.mark.MarkDecorator` object
- created by a call to ``py.test.mark.NAME(...)``.
- """
- if not isinstance(marker, pytest.mark.XYZ.__class__):
- raise ValueError("%r is not a py.test.mark.* object")
- setattr(self.markers, marker.markname, marker)
-
#def extrainit(self):
# """"extra initialization after Node is initialized. Implemented
# by some subclasses. """