[py-svn] r61831 - in py/branch/pytestplugin/py/test: . testing

hpk at codespeak.net hpk at codespeak.net
Fri Feb 13 15:30:03 CET 2009


Author: hpk
Date: Fri Feb 13 15:29:59 2009
New Revision: 61831

Added:
   py/branch/pytestplugin/py/test/handleplugin.py   (contents, props changed)
   py/branch/pytestplugin/py/test/testing/test_handleplugin.py   (contents, props changed)
Log:
draft of initial glue code to use the new event/plugin mechanisms for the existing py.test plugins


Added: py/branch/pytestplugin/py/test/handleplugin.py
==============================================================================
--- (empty file)
+++ py/branch/pytestplugin/py/test/handleplugin.py	Fri Feb 13 15:29:59 2009
@@ -0,0 +1,34 @@
+"""
+handling py.test related plugins 
+"""
+import py
+
+class PytestPluginManager(object):
+    def __init__(self, pluginmanager=py.plugin):
+        self.pm = pluginmanager 
+
+    #
+    # API for interacting with registered and instantiated plugin objects 
+    #
+    def setinitial(self, modules):
+        for module in modules:
+            self.pm.consider_module(module)
+
+    def add_cmdlineoptions(self, config):
+        # XXX think about sorting/grouping of options from user-perspective 
+        opts = []
+        for name, options in self.pm.iterattr("pytest_cmdlineoptions"):
+            opts.extend(options)
+        config.addoptions("ungrouped options added by plugins", *opts) 
+
+    def ensure_configured_plugins(self, config):
+        def configureplugin(plugin):
+            self.pm.callone(plugin, "pytest_configure", config=config)
+        self.configureplugin = configureplugin
+        self.pm.subscribe(pluginregistered=autoconfigure)
+        self.pm.callplugins("pytest_configure", config=config) 
+
+    def unconfigure_plugins(self, config):
+        self.pm.callplugins("pytest_unconfigure", config=config)
+        self.pm.unsubscribe(pluginregistered=self.configureplugin)
+        del self.configureplugin

Added: py/branch/pytestplugin/py/test/testing/test_handleplugin.py
==============================================================================
--- (empty file)
+++ py/branch/pytestplugin/py/test/testing/test_handleplugin.py	Fri Feb 13 15:29:59 2009
@@ -0,0 +1,18 @@
+import py
+from py.__.test.handleplugin import PytestPluginManager
+
+def test_addcmdlineoptions():
+    class PseudoPM:
+        def iterattr(self, name):
+            assert name == "pytest_cmdlineoptions"
+            return [("xxx", 
+             [py.std.optparse.Option("--pseudopm", action="store", dest="x")])]
+    class PseudoConfig:
+        opts = []
+        def addoptions(self, *opts):
+            self.opts.append(opts) 
+    pseudopm = PseudoPM()
+    pseudoconfig = PseudoConfig()
+    pc = PytestPluginManager(pseudopm) 
+    pc.add_cmdlineoptions(pseudoconfig)
+    assert len(pseudoconfig.opts) == 1



More information about the pytest-commit mailing list