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

hpk at codespeak.net hpk at codespeak.net
Fri Jan 23 16:22:13 CET 2009


Author: hpk
Date: Fri Jan 23 16:22:10 2009
New Revision: 61265

Modified:
   py/branch/pytestplugin/py/test/config.py
   py/branch/pytestplugin/py/test/pmanage.py
   py/branch/pytestplugin/py/test/testing/test_pmanage.py
Log:
move plugin registration and initilaization into pluginmanager, with tests. 


Modified: py/branch/pytestplugin/py/test/config.py
==============================================================================
--- py/branch/pytestplugin/py/test/config.py	(original)
+++ py/branch/pytestplugin/py/test/config.py	Fri Jan 23 16:22:10 2009
@@ -37,20 +37,6 @@
         self._conftest = Conftest()
         self.pluginmanager = PluginManager()
 
-    def _initplugins(self):
-        for mod in self._conftest.getconftestmodules(None):
-            self.pluginmanager.consider_module(mod)
-
-    def _bootstrapcmdlineconfig(self, args):
-        adddefaultoptions(self)
-        self._conftest.setinitial(args)
-        self._initplugins()
-        # XXX think about sorting/grouping of options from user-perspective 
-        opts = []
-        for name, options in self.pluginmanager.listattr("pytest_cmdlineoptions"):
-            opts.extend(options)
-        self.addoptions("ungrouped options added by plugins", *opts) 
-
     def parse(self, args): 
         """ parse cmdline arguments into this config object. 
             Note that this can only be called once per testing process. 
@@ -58,7 +44,10 @@
         assert not self._initialized, (
                 "can only parse cmdline args at most once per Config object")
         self._initialized = True
-        self._bootstrapcmdlineconfig(args)
+        adddefaultoptions(self)
+        self._conftest.setinitial(args)
+        self.pluginmanager.registerplugins(self._conftest.getconftestmodules(None))
+        self.pluginmanager.add_cmdlineoptions(self)
         args = [str(x) for x in args]
         cmdlineoption, args = self._parser.parse_args(args) 
         self.option.__dict__.update(vars(cmdlineoption))
@@ -81,7 +70,7 @@
         self._initialized = True
         self.topdir = py.path.local(topdir)
         self._mergerepr(self._repr)
-        self._initplugins()
+        self.pluginmanager.registerplugins(self._conftest.getconftestmodules(None))
         del self._repr 
 
     def _makerepr(self):

Modified: py/branch/pytestplugin/py/test/pmanage.py
==============================================================================
--- py/branch/pytestplugin/py/test/pmanage.py	(original)
+++ py/branch/pytestplugin/py/test/pmanage.py	Fri Jan 23 16:22:10 2009
@@ -41,8 +41,19 @@
             if spec:
                 self.import_plugin(spec) 
 
+    def registerplugins(self, conftestmodules):
+        for mod in conftestmodules:
+            self.consider_module(mod)
+
+    def add_cmdlineoptions(self, config):
+        # XXX think about sorting/grouping of options from user-perspective 
+        opts = []
+        for name, options in self.listattr("pytest_cmdlineoptions"):
+            opts.extend(options)
+        config.addoptions("ungrouped options added by plugins", *opts) 
+
     #
-    # API for calling methods of the plugins 
+    # API for calling methods of registered plugins 
     #
     def callplugins(self, methname, **args):
         for name, method in self.listattr(methname):

Modified: py/branch/pytestplugin/py/test/testing/test_pmanage.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_pmanage.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_pmanage.py	Fri Jan 23 16:22:10 2009
@@ -39,6 +39,18 @@
         finally:
             sys.path.remove(str(self.tmpdir))
 
+    def test_register_plugins(self):
+        pm = PluginManager()
+        sys.path.insert(0, str(self.tmpdir))
+        try:
+            self.tmpdir.join("pytest_rplug.py").write("class Rplug: pass")
+            mod = py.std.new.module("temp")
+            mod.pytest_plugins_required = ["pytest_rplug"]
+            pm.registerplugins([mod])
+            assert pm.getplugin("rplug").__class__.__name__ == "Rplug"
+        finally:
+            sys.path.remove(str(self.tmpdir))
+
     def test_addpluginclass(self):
         pm = PluginManager()
         class My:
@@ -86,3 +98,17 @@
         pm.forward_event(ev)
         assert len(l) == 1
         assert l[0] is ev
+
+    def test_addcmdlineoptions(self):
+        from py.__.test.config import Config 
+        pm = PluginManager()
+        class My:
+            pytest_cmdlineoptions = [
+                py.test.config.Option("--hello", dest="dest", default=242)
+            ]
+        pm.addpluginclass(My)
+        config = Config()
+        pm.add_cmdlineoptions(config)
+        opt = config._parser.get_option("--hello")
+        assert opt
+        assert opt.default == 242



More information about the pytest-commit mailing list