[py-svn] commit/pytest: hpk42: offer a semi-internal method to create a config object in subprocesses

Bitbucket commits-noreply at bitbucket.org
Wed Mar 16 18:01:30 CET 2011


1 new changeset in pytest:

http://bitbucket.org/hpk42/pytest/changeset/6f036850385f/
changeset:   r2189:6f036850385f
user:        hpk42
date:        2011-03-16 18:00:52
summary:     offer a semi-internal method to create a config object in subprocesses
(helps pytest-xdist plugin to fix issue34)
affected #:  2 files (373 bytes)

--- a/_pytest/config.py	Wed Mar 16 16:36:18 2011 +0100
+++ b/_pytest/config.py	Wed Mar 16 18:00:52 2011 +0100
@@ -252,6 +252,16 @@
         self.hook = self.pluginmanager.hook
         self._inicache = {}
 
+    @classmethod
+    def fromdictargs(cls, option_dict, args):
+        """ constructor useable for subprocesses. """
+        config = cls()
+        config._preparse(args, addopts=False)
+        config.option.__dict__.update(option_dict)
+        for x in config.option.plugins:
+            config.pluginmanager.consider_pluginarg(x)
+        return config
+
     def _onimportconftest(self, conftestmodule):
         self.trace("loaded conftestmodule %r" %(conftestmodule,))
         self.pluginmanager.consider_conftest(conftestmodule)


--- a/_pytest/core.py	Wed Mar 16 16:36:18 2011 +0100
+++ b/_pytest/core.py	Wed Mar 16 18:00:52 2011 +0100
@@ -164,14 +164,17 @@
     def consider_preparse(self, args):
         for opt1,opt2 in zip(args, args[1:]):
             if opt1 == "-p":
-                if opt2.startswith("no:"):
-                    name = opt2[3:]
-                    if self.getplugin(name) is not None:
-                        self.unregister(None, name=name)
-                    self._name2plugin[name] = -1
-                else:
-                    if self.getplugin(opt2) is None:
-                        self.import_plugin(opt2)
+                self.consider_pluginarg(opt2)
+
+    def consider_pluginarg(self, arg):
+        if arg.startswith("no:"):
+            name = arg[3:]
+            if self.getplugin(name) is not None:
+                self.unregister(None, name=name)
+            self._name2plugin[name] = -1
+        else:
+            if self.getplugin(arg) is None:
+                self.import_plugin(arg)
 
     def consider_conftest(self, conftestmodule):
         if self.register(conftestmodule, name=conftestmodule.__file__):

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list