[py-svn] pytest commit cfcf15d0d1e4: simplify pluginlist computation

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Nov 24 22:26:16 CET 2010


# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User holger krekel <holger at merlinux.eu>
# Date 1290633772 -3600
# Node ID cfcf15d0d1e4aa25a9d6d45f59f5b6e92a19ed1e
# Parent  ae80b0f9d8ed34cc84e96d4175beb89e81541120
simplify pluginlist computation

--- a/_pytest/session.py
+++ b/_pytest/session.py
@@ -221,6 +221,9 @@ class Node(object):
     def listnames(self):
         return [x.name for x in self.listchain()]
 
+    def getplugins(self):
+        return self.config._getmatchingplugins(self.fspath)
+
     def getparent(self, cls):
         current = self
         while current and not isinstance(current, cls):

--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -208,7 +208,10 @@ class PyCollectorMixin(PyobjMixin, pytes
         metafunc = Metafunc(funcobj, config=self.config,
             cls=cls, module=module)
         gentesthook = self.config.hook.pytest_generate_tests
-        plugins = getplugins(self, withpy=True)
+        extra = [module]
+        if cls is not None:
+            extra.append(cls())
+        plugins = self.getplugins() + extra
         gentesthook.pcall(plugins, metafunc=metafunc)
         if not metafunc._calls:
             return Function(name, parent=self)
@@ -497,17 +500,6 @@ def fillfuncargs(function):
     request = FuncargRequest(pyfuncitem=function)
     request._fillfuncargs()
 
-def getplugins(node, withpy=False): # might by any node
-    plugins = node.config._getmatchingplugins(node.fspath)
-    if withpy:
-        mod = node.getparent(pytest.Module)
-        if mod is not None:
-            plugins.append(mod.obj)
-        inst = node.getparent(pytest.Instance)
-        if inst is not None:
-            plugins.append(inst.obj)
-    return plugins
-
 _notexists = object()
 class CallSpec:
     def __init__(self, funcargs, id, param):
@@ -572,7 +564,8 @@ class FuncargRequest:
         self._pyfuncitem = pyfuncitem
         if hasattr(pyfuncitem, '_requestparam'):
             self.param = pyfuncitem._requestparam
-        self._plugins = getplugins(pyfuncitem, withpy=True)
+        extra = filter(None, [self.module, self.instance])
+        self._plugins = pyfuncitem.getplugins() + extra
         self._funcargs  = self._pyfuncitem.funcargs.copy()
         self._name2factory = {}
         self._currentarg = None
@@ -741,9 +734,9 @@ def showfuncargs(config):
     session = Session(config)
     session.perform_collect()
     if session.items:
-        plugins = getplugins(session.items[0])
+        plugins = session.items[0].getplugins()
     else:
-        plugins = getplugins(session)
+        plugins = session.getplugins()
     curdir = py.path.local()
     tw = py.io.TerminalWriter()
     verbose = config.getvalue("verbose")



More information about the pytest-commit mailing list