From 0361b73d75870f434b0055c495ce578e212bf133 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 29 Dec 2009 10:26:51 +0100 Subject: [PATCH] remove defaultconfest.py and make PluginManager directly do early initialization of default plugins. --HG-- branch : trunk --- py/impl/test/collect.py | 2 +- py/impl/test/config.py | 9 ++++++++- py/impl/test/conftesthandle.py | 3 +-- py/impl/test/defaultconftest.py | 14 -------------- py/impl/test/pluginmanager.py | 23 ++++++++++++----------- py/plugin/pytest_default.py | 2 +- testing/plugin/conftest.py | 2 +- testing/pytest/test_conftesthandle.py | 14 +++++++------- testing/pytest/test_pickling.py | 2 +- testing/pytest/test_pluginmanager.py | 9 ++++++--- 10 files changed, 38 insertions(+), 42 deletions(-) delete mode 100644 py/impl/test/defaultconftest.py diff --git a/py/impl/test/collect.py b/py/impl/test/collect.py index 02a0ec2a4..fd667d0e2 100644 --- a/py/impl/test/collect.py +++ b/py/impl/test/collect.py @@ -8,7 +8,7 @@ import py def configproperty(name): def fget(self): #print "retrieving %r property from %s" %(name, self.fspath) - return self.config.getvalue(name, self.fspath) + return self.config._getcollectclass(name, self.fspath) return property(fget) class Node(object): diff --git a/py/impl/test/config.py b/py/impl/test/config.py index a74384ba6..038aa7dd6 100644 --- a/py/impl/test/config.py +++ b/py/impl/test/config.py @@ -107,6 +107,7 @@ class Config(object): # warning global side effects: # * registering to py lib plugins # * setting py.test.config + py._com.comregistry = py._com.Registry() self.__init__( pluginmanager=py.test._PluginManager(py._com.comregistry), topdir=py.path.local(), @@ -155,11 +156,17 @@ class Config(object): pkgpath = path.pypkgpath() if pkgpath is None: pkgpath = path.check(file=1) and path.dirpath() or path - Dir = self._conftest.rget("Directory", pkgpath) + Dir = self._getcollectclass("Directory", pkgpath) col = Dir(pkgpath) col.config = self return col._getfsnode(path) + def _getcollectclass(self, name, path): + try: + return self.getvalue(name, path) + except KeyError: + return getattr(py.test.collect, name) + def getconftest_pathlist(self, name, path=None): """ return a matching value, which needs to be sequence of filenames that will be returned as a list of Path diff --git a/py/impl/test/conftesthandle.py b/py/impl/test/conftesthandle.py index 1c01e310d..08aa4c13e 100644 --- a/py/impl/test/conftesthandle.py +++ b/py/impl/test/conftesthandle.py @@ -1,5 +1,4 @@ import py -from py.impl.test import defaultconftest class Conftest(object): """ the single place for accessing values and interacting @@ -40,7 +39,7 @@ class Conftest(object): raise ValueError("missing default conftest.") dp = path.dirpath() if dp == path: - clist = [self._postimport(defaultconftest)] + clist = self._path2confmods[path] = [] else: clist = self.getconftestmodules(dp) conftestpath = path.join("conftest.py") diff --git a/py/impl/test/defaultconftest.py b/py/impl/test/defaultconftest.py deleted file mode 100644 index 83a988f37..000000000 --- a/py/impl/test/defaultconftest.py +++ /dev/null @@ -1,14 +0,0 @@ -import py - -Module = py.test.collect.Module -Directory = py.test.collect.Directory -File = py.test.collect.File - -# python collectors -Class = py.test.collect.Class -Generator = py.test.collect.Generator -Function = py.test.collect.Function -Instance = py.test.collect.Instance - -pytest_plugins = "default runner capture terminal mark skipping tmpdir monkeypatch recwarn pdb pastebin unittest helpconfig nose assertion".split() - diff --git a/py/impl/test/pluginmanager.py b/py/impl/test/pluginmanager.py index c093d9549..7f070896c 100644 --- a/py/impl/test/pluginmanager.py +++ b/py/impl/test/pluginmanager.py @@ -5,6 +5,10 @@ import py from py.plugin import hookspec from py.impl.test.outcome import Skipped +default_plugins = ( + "default runner capture terminal mark skipping tmpdir monkeypatch " + "recwarn pdb pastebin unittest helpconfig nose assertion").split() + def check_old_use(mod, modname): clsname = modname[len('pytest_'):].capitalize() + "Plugin" assert not hasattr(mod, clsname), (mod, clsname) @@ -21,6 +25,9 @@ class PluginManager(object): self.hook = py._com.HookRelay( hookspecs=hookspec, registry=self.comregistry) + self.register(self) + for spec in default_plugins: + self.import_plugin(spec) def _getpluginname(self, plugin, name): if name is None: @@ -31,7 +38,8 @@ class PluginManager(object): return name def register(self, plugin, name=None): - assert not self.isregistered(plugin) + assert not self.isregistered(plugin), plugin + assert not self.comregistry.isregistered(plugin), plugin name = self._getpluginname(plugin, name) if name in self._name2plugin: return False @@ -191,31 +199,24 @@ class PluginManager(object): mc.execute() def pytest_plugin_registered(self, plugin): + dic = self.call_plugin(plugin, "pytest_namespace", {}) or {} + for name, value in dic.items(): + setattr(py.test, name, value) if hasattr(self, '_config'): self.call_plugin(plugin, "pytest_addoption", {'parser': self._config._parser}) self.call_plugin(plugin, "pytest_configure", {'config': self._config}) - #dic = self.call_plugin(plugin, "pytest_namespace") - #self._updateext(dic) def call_plugin(self, plugin, methname, kwargs): return py._com.MultiCall( methods=self.listattr(methname, plugins=[plugin]), kwargs=kwargs, firstresult=True).execute() - def _updateext(self, dic): - if dic: - for name, value in dic.items(): - setattr(py.test, name, value) - def do_configure(self, config): assert not hasattr(self, '_config') - config.pluginmanager.register(self) self._config = config config.hook.pytest_configure(config=self._config) - for dic in config.hook.pytest_namespace() or []: - self._updateext(dic) def do_unconfigure(self, config): config = self._config diff --git a/py/plugin/pytest_default.py b/py/plugin/pytest_default.py index 1f71398d8..0c3a4fd15 100644 --- a/py/plugin/pytest_default.py +++ b/py/plugin/pytest_default.py @@ -40,7 +40,7 @@ def pytest_collect_directory(path, parent): break else: return - Directory = parent.config.getvalue('Directory', path) + Directory = parent.config._getcollectclass('Directory', path) return Directory(path, parent=parent) def pytest_report_iteminfo(item): diff --git a/testing/plugin/conftest.py b/testing/plugin/conftest.py index 97d167f18..092d9d417 100644 --- a/testing/plugin/conftest.py +++ b/testing/plugin/conftest.py @@ -3,7 +3,7 @@ import py pytest_plugins = "pytester" import py.plugin plugindir = py.path.local(py.plugin.__file__).dirpath() -from py.impl.test.defaultconftest import pytest_plugins as default_plugins +from py.impl.test.pluginmanager import default_plugins def pytest_collect_file(path, parent): if path.basename.startswith("pytest_") and path.ext == ".py": diff --git a/testing/pytest/test_conftesthandle.py b/testing/pytest/test_conftesthandle.py index 1d1038510..2dbc25967 100644 --- a/testing/pytest/test_conftesthandle.py +++ b/testing/pytest/test_conftesthandle.py @@ -32,10 +32,10 @@ class TestConftestValueAccessGlobal: l = [] conftest = Conftest(onimport=l.append) conftest.setinitial([basedir.join("adir")]) - assert len(l) == 2 # default + the one + assert len(l) == 1 assert conftest.rget("a") == 1 assert conftest.rget("b", basedir.join("adir", "b")) == 2 - assert len(l) == 3 + assert len(l) == 2 def test_immediate_initialiation_and_incremental_are_the_same(self, basedir): conftest = Conftest() @@ -48,11 +48,11 @@ class TestConftestValueAccessGlobal: conftest.getconftestmodules(basedir.join('b')) assert len(conftest._path2confmods) == snap1 + 2 - def test_default_Module_setting_is_visible_always(self, basedir): - for path in basedir.parts(): - conftest = ConftestWithSetinitial(path) - #assert conftest.lget("Module") == py.test.collect.Module - assert conftest.rget("Module") == py.test.collect.Module + def test_default_Module_setting_is_visible_always(self, basedir, testdir): + basedir.copy(testdir.tmpdir) + config = testdir.Config() + colclass = config._getcollectclass("Module", testdir.tmpdir) + assert colclass == py.test.collect.Module def test_default_has_lower_prio(self, basedir): conftest = ConftestWithSetinitial(basedir.join("adir")) diff --git a/testing/pytest/test_pickling.py b/testing/pytest/test_pickling.py index 54f5bcaf6..ec275a36b 100644 --- a/testing/pytest/test_pickling.py +++ b/testing/pytest/test_pickling.py @@ -184,7 +184,7 @@ class TestConfigPickling: def test_config__setstate__wired_correctly_in_childprocess(testdir): execnet = py.test.importorskip("execnet") from py.impl.test.dist.mypickle import PickleChannel - gw = execnet.PopenGateway() + gw = execnet.makegateway() channel = gw.remote_exec(""" import py from py.impl.test.dist.mypickle import PickleChannel diff --git a/testing/pytest/test_pluginmanager.py b/testing/pytest/test_pluginmanager.py index 63905033c..3620ec92b 100644 --- a/testing/pytest/test_pluginmanager.py +++ b/testing/pytest/test_pluginmanager.py @@ -148,7 +148,9 @@ class TestBootstrapping: assert pp.isregistered(a1) pp.register(a2, "hello") assert pp.isregistered(a2) - assert pp.getplugins() == [a1, a2] + l = pp.getplugins() + assert a1 in l + assert a2 in l assert pp.getplugin('hello') == a2 pp.unregister(a1) assert not pp.isregistered(a1) @@ -160,13 +162,14 @@ class TestBootstrapping: mod = py.std.types.ModuleType("x.y.pytest_hello") pp.register(mod) assert pp.isregistered(mod) - assert pp.getplugins() == [mod] + l = pp.getplugins() + assert mod in l py.test.raises(AssertionError, "pp.register(mod)") mod2 = py.std.types.ModuleType("pytest_hello") #pp.register(mod2) # double registry py.test.raises(AssertionError, "pp.register(mod)") #assert not pp.isregistered(mod2) - assert pp.getplugins() == [mod] # does not actually modify plugins + assert pp.getplugins() == l def test_canonical_import(self, monkeypatch): mod = py.std.types.ModuleType("pytest_xyz")