remove defaultconfest.py and make PluginManager directly do early initialization of default plugins.
--HG-- branch : trunk
This commit is contained in:
parent
27bcd2dbda
commit
0361b73d75
|
@ -8,7 +8,7 @@ import py
|
||||||
def configproperty(name):
|
def configproperty(name):
|
||||||
def fget(self):
|
def fget(self):
|
||||||
#print "retrieving %r property from %s" %(name, self.fspath)
|
#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)
|
return property(fget)
|
||||||
|
|
||||||
class Node(object):
|
class Node(object):
|
||||||
|
|
|
@ -107,6 +107,7 @@ class Config(object):
|
||||||
# warning global side effects:
|
# warning global side effects:
|
||||||
# * registering to py lib plugins
|
# * registering to py lib plugins
|
||||||
# * setting py.test.config
|
# * setting py.test.config
|
||||||
|
py._com.comregistry = py._com.Registry()
|
||||||
self.__init__(
|
self.__init__(
|
||||||
pluginmanager=py.test._PluginManager(py._com.comregistry),
|
pluginmanager=py.test._PluginManager(py._com.comregistry),
|
||||||
topdir=py.path.local(),
|
topdir=py.path.local(),
|
||||||
|
@ -155,11 +156,17 @@ class Config(object):
|
||||||
pkgpath = path.pypkgpath()
|
pkgpath = path.pypkgpath()
|
||||||
if pkgpath is None:
|
if pkgpath is None:
|
||||||
pkgpath = path.check(file=1) and path.dirpath() or path
|
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 = Dir(pkgpath)
|
||||||
col.config = self
|
col.config = self
|
||||||
return col._getfsnode(path)
|
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):
|
def getconftest_pathlist(self, name, path=None):
|
||||||
""" return a matching value, which needs to be sequence
|
""" return a matching value, which needs to be sequence
|
||||||
of filenames that will be returned as a list of Path
|
of filenames that will be returned as a list of Path
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import py
|
import py
|
||||||
from py.impl.test import defaultconftest
|
|
||||||
|
|
||||||
class Conftest(object):
|
class Conftest(object):
|
||||||
""" the single place for accessing values and interacting
|
""" the single place for accessing values and interacting
|
||||||
|
@ -40,7 +39,7 @@ class Conftest(object):
|
||||||
raise ValueError("missing default conftest.")
|
raise ValueError("missing default conftest.")
|
||||||
dp = path.dirpath()
|
dp = path.dirpath()
|
||||||
if dp == path:
|
if dp == path:
|
||||||
clist = [self._postimport(defaultconftest)]
|
clist = self._path2confmods[path] = []
|
||||||
else:
|
else:
|
||||||
clist = self.getconftestmodules(dp)
|
clist = self.getconftestmodules(dp)
|
||||||
conftestpath = path.join("conftest.py")
|
conftestpath = path.join("conftest.py")
|
||||||
|
|
|
@ -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()
|
|
||||||
|
|
|
@ -5,6 +5,10 @@ import py
|
||||||
from py.plugin import hookspec
|
from py.plugin import hookspec
|
||||||
from py.impl.test.outcome import Skipped
|
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):
|
def check_old_use(mod, modname):
|
||||||
clsname = modname[len('pytest_'):].capitalize() + "Plugin"
|
clsname = modname[len('pytest_'):].capitalize() + "Plugin"
|
||||||
assert not hasattr(mod, clsname), (mod, clsname)
|
assert not hasattr(mod, clsname), (mod, clsname)
|
||||||
|
@ -21,6 +25,9 @@ class PluginManager(object):
|
||||||
self.hook = py._com.HookRelay(
|
self.hook = py._com.HookRelay(
|
||||||
hookspecs=hookspec,
|
hookspecs=hookspec,
|
||||||
registry=self.comregistry)
|
registry=self.comregistry)
|
||||||
|
self.register(self)
|
||||||
|
for spec in default_plugins:
|
||||||
|
self.import_plugin(spec)
|
||||||
|
|
||||||
def _getpluginname(self, plugin, name):
|
def _getpluginname(self, plugin, name):
|
||||||
if name is None:
|
if name is None:
|
||||||
|
@ -31,7 +38,8 @@ class PluginManager(object):
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def register(self, plugin, name=None):
|
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)
|
name = self._getpluginname(plugin, name)
|
||||||
if name in self._name2plugin:
|
if name in self._name2plugin:
|
||||||
return False
|
return False
|
||||||
|
@ -191,31 +199,24 @@ class PluginManager(object):
|
||||||
mc.execute()
|
mc.execute()
|
||||||
|
|
||||||
def pytest_plugin_registered(self, plugin):
|
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'):
|
if hasattr(self, '_config'):
|
||||||
self.call_plugin(plugin, "pytest_addoption",
|
self.call_plugin(plugin, "pytest_addoption",
|
||||||
{'parser': self._config._parser})
|
{'parser': self._config._parser})
|
||||||
self.call_plugin(plugin, "pytest_configure",
|
self.call_plugin(plugin, "pytest_configure",
|
||||||
{'config': self._config})
|
{'config': self._config})
|
||||||
#dic = self.call_plugin(plugin, "pytest_namespace")
|
|
||||||
#self._updateext(dic)
|
|
||||||
|
|
||||||
def call_plugin(self, plugin, methname, kwargs):
|
def call_plugin(self, plugin, methname, kwargs):
|
||||||
return py._com.MultiCall(
|
return py._com.MultiCall(
|
||||||
methods=self.listattr(methname, plugins=[plugin]),
|
methods=self.listattr(methname, plugins=[plugin]),
|
||||||
kwargs=kwargs, firstresult=True).execute()
|
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):
|
def do_configure(self, config):
|
||||||
assert not hasattr(self, '_config')
|
assert not hasattr(self, '_config')
|
||||||
config.pluginmanager.register(self)
|
|
||||||
self._config = config
|
self._config = config
|
||||||
config.hook.pytest_configure(config=self._config)
|
config.hook.pytest_configure(config=self._config)
|
||||||
for dic in config.hook.pytest_namespace() or []:
|
|
||||||
self._updateext(dic)
|
|
||||||
|
|
||||||
def do_unconfigure(self, config):
|
def do_unconfigure(self, config):
|
||||||
config = self._config
|
config = self._config
|
||||||
|
|
|
@ -40,7 +40,7 @@ def pytest_collect_directory(path, parent):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
Directory = parent.config.getvalue('Directory', path)
|
Directory = parent.config._getcollectclass('Directory', path)
|
||||||
return Directory(path, parent=parent)
|
return Directory(path, parent=parent)
|
||||||
|
|
||||||
def pytest_report_iteminfo(item):
|
def pytest_report_iteminfo(item):
|
||||||
|
|
|
@ -3,7 +3,7 @@ import py
|
||||||
pytest_plugins = "pytester"
|
pytest_plugins = "pytester"
|
||||||
import py.plugin
|
import py.plugin
|
||||||
plugindir = py.path.local(py.plugin.__file__).dirpath()
|
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):
|
def pytest_collect_file(path, parent):
|
||||||
if path.basename.startswith("pytest_") and path.ext == ".py":
|
if path.basename.startswith("pytest_") and path.ext == ".py":
|
||||||
|
|
|
@ -32,10 +32,10 @@ class TestConftestValueAccessGlobal:
|
||||||
l = []
|
l = []
|
||||||
conftest = Conftest(onimport=l.append)
|
conftest = Conftest(onimport=l.append)
|
||||||
conftest.setinitial([basedir.join("adir")])
|
conftest.setinitial([basedir.join("adir")])
|
||||||
assert len(l) == 2 # default + the one
|
assert len(l) == 1
|
||||||
assert conftest.rget("a") == 1
|
assert conftest.rget("a") == 1
|
||||||
assert conftest.rget("b", basedir.join("adir", "b")) == 2
|
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):
|
def test_immediate_initialiation_and_incremental_are_the_same(self, basedir):
|
||||||
conftest = Conftest()
|
conftest = Conftest()
|
||||||
|
@ -48,11 +48,11 @@ class TestConftestValueAccessGlobal:
|
||||||
conftest.getconftestmodules(basedir.join('b'))
|
conftest.getconftestmodules(basedir.join('b'))
|
||||||
assert len(conftest._path2confmods) == snap1 + 2
|
assert len(conftest._path2confmods) == snap1 + 2
|
||||||
|
|
||||||
def test_default_Module_setting_is_visible_always(self, basedir):
|
def test_default_Module_setting_is_visible_always(self, basedir, testdir):
|
||||||
for path in basedir.parts():
|
basedir.copy(testdir.tmpdir)
|
||||||
conftest = ConftestWithSetinitial(path)
|
config = testdir.Config()
|
||||||
#assert conftest.lget("Module") == py.test.collect.Module
|
colclass = config._getcollectclass("Module", testdir.tmpdir)
|
||||||
assert conftest.rget("Module") == py.test.collect.Module
|
assert colclass == py.test.collect.Module
|
||||||
|
|
||||||
def test_default_has_lower_prio(self, basedir):
|
def test_default_has_lower_prio(self, basedir):
|
||||||
conftest = ConftestWithSetinitial(basedir.join("adir"))
|
conftest = ConftestWithSetinitial(basedir.join("adir"))
|
||||||
|
|
|
@ -184,7 +184,7 @@ class TestConfigPickling:
|
||||||
def test_config__setstate__wired_correctly_in_childprocess(testdir):
|
def test_config__setstate__wired_correctly_in_childprocess(testdir):
|
||||||
execnet = py.test.importorskip("execnet")
|
execnet = py.test.importorskip("execnet")
|
||||||
from py.impl.test.dist.mypickle import PickleChannel
|
from py.impl.test.dist.mypickle import PickleChannel
|
||||||
gw = execnet.PopenGateway()
|
gw = execnet.makegateway()
|
||||||
channel = gw.remote_exec("""
|
channel = gw.remote_exec("""
|
||||||
import py
|
import py
|
||||||
from py.impl.test.dist.mypickle import PickleChannel
|
from py.impl.test.dist.mypickle import PickleChannel
|
||||||
|
|
|
@ -148,7 +148,9 @@ class TestBootstrapping:
|
||||||
assert pp.isregistered(a1)
|
assert pp.isregistered(a1)
|
||||||
pp.register(a2, "hello")
|
pp.register(a2, "hello")
|
||||||
assert pp.isregistered(a2)
|
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
|
assert pp.getplugin('hello') == a2
|
||||||
pp.unregister(a1)
|
pp.unregister(a1)
|
||||||
assert not pp.isregistered(a1)
|
assert not pp.isregistered(a1)
|
||||||
|
@ -160,13 +162,14 @@ class TestBootstrapping:
|
||||||
mod = py.std.types.ModuleType("x.y.pytest_hello")
|
mod = py.std.types.ModuleType("x.y.pytest_hello")
|
||||||
pp.register(mod)
|
pp.register(mod)
|
||||||
assert pp.isregistered(mod)
|
assert pp.isregistered(mod)
|
||||||
assert pp.getplugins() == [mod]
|
l = pp.getplugins()
|
||||||
|
assert mod in l
|
||||||
py.test.raises(AssertionError, "pp.register(mod)")
|
py.test.raises(AssertionError, "pp.register(mod)")
|
||||||
mod2 = py.std.types.ModuleType("pytest_hello")
|
mod2 = py.std.types.ModuleType("pytest_hello")
|
||||||
#pp.register(mod2) # double registry
|
#pp.register(mod2) # double registry
|
||||||
py.test.raises(AssertionError, "pp.register(mod)")
|
py.test.raises(AssertionError, "pp.register(mod)")
|
||||||
#assert not pp.isregistered(mod2)
|
#assert not pp.isregistered(mod2)
|
||||||
assert pp.getplugins() == [mod] # does not actually modify plugins
|
assert pp.getplugins() == l
|
||||||
|
|
||||||
def test_canonical_import(self, monkeypatch):
|
def test_canonical_import(self, monkeypatch):
|
||||||
mod = py.std.types.ModuleType("pytest_xyz")
|
mod = py.std.types.ModuleType("pytest_xyz")
|
||||||
|
|
Loading…
Reference in New Issue