diff --git a/py/_com.py b/py/_com.py index a42fd56c3..97c3e59d0 100644 --- a/py/_com.py +++ b/py/_com.py @@ -71,27 +71,27 @@ class Registry: def __init__(self, plugins=None): if plugins is None: plugins = [] - self.plugins = plugins + self._plugins = plugins def register(self, plugin): assert not isinstance(plugin, str) self.call_each("pytest_plugin_registered", plugin) - self.plugins.append(plugin) + self._plugins.append(plugin) def unregister(self, plugin): self.call_each("pytest_plugin_unregistered", plugin) - self.plugins.remove(plugin) + self._plugins.remove(plugin) def isregistered(self, plugin): - return plugin in self.plugins + return plugin in self._plugins def __iter__(self): - return iter(self.plugins) + return iter(self._plugins) def listattr(self, attrname, plugins=None, extra=(), reverse=False): l = [] if plugins is None: - plugins = self.plugins + plugins = self._plugins if extra: plugins += list(extra) for plugin in plugins: @@ -117,31 +117,31 @@ class Registry: class PluginAPI: - def __init__(self, apiclass, plugins=None): + def __init__(self, apiclass, registry=None): self._apiclass = apiclass - if plugins is None: - plugins = comregistry - self.plugins = plugins + if registry is None: + registry = comregistry + self.registry = registry for name, method in vars(apiclass).items(): if name[:2] != "__": firstresult = getattr(method, 'firstresult', False) - mm = ApiCall(plugins, name, firstresult=firstresult) + mm = ApiCall(registry, name, firstresult=firstresult) setattr(self, name, mm) def __repr__(self): - return "" %(self._apiclass, self.plugins) + return "" %(self._apiclass, self._plugins) class ApiCall: - def __init__(self, plugins, name, firstresult): - self.plugins = plugins + def __init__(self, registry, name, firstresult): + self.registry = registry self.name = name self.firstresult = firstresult def __repr__(self): mode = self.firstresult and "firstresult" or "each" - return "" %(self.name, mode, self.plugins) + return "" %(self.name, mode, self.registry) def __call__(self, *args, **kwargs): - mc = MultiCall(self.plugins.listattr(self.name), *args, **kwargs) + mc = MultiCall(self.registry.listattr(self.name), *args, **kwargs) #print "making multicall", self return mc.execute(firstresult=self.firstresult) diff --git a/py/misc/testing/test_com.py b/py/misc/testing/test_com.py index 50cbe4386..7364d0d35 100644 --- a/py/misc/testing/test_com.py +++ b/py/misc/testing/test_com.py @@ -165,37 +165,37 @@ def test_api_and_defaults(): class TestPluginAPI: def test_happypath(self): - plugins = Registry() + registry = Registry() class Api: def hello(self, arg): pass - mcm = PluginAPI(apiclass=Api, plugins=plugins) + mcm = PluginAPI(apiclass=Api, registry=registry) assert hasattr(mcm, 'hello') assert repr(mcm.hello).find("hello") != -1 class Plugin: def hello(self, arg): return arg + 1 - plugins.register(Plugin()) + registry.register(Plugin()) l = mcm.hello(3) assert l == [4] assert not hasattr(mcm, 'world') def test_firstresult(self): - plugins = Registry() + registry = Registry() class Api: def hello(self, arg): pass hello.firstresult = True - mcm = PluginAPI(apiclass=Api, plugins=plugins) + mcm = PluginAPI(apiclass=Api, registry=registry) class Plugin: def hello(self, arg): return arg + 1 - plugins.register(Plugin()) + registry.register(Plugin()) res = mcm.hello(3) assert res == 4 def test_default_plugins(self): class Api: pass mcm = PluginAPI(apiclass=Api) - assert mcm.plugins == py._com.comregistry + assert mcm.registry == py._com.comregistry diff --git a/py/test/pluginmanager.py b/py/test/pluginmanager.py index bce60ea86..e43e968ad 100644 --- a/py/test/pluginmanager.py +++ b/py/test/pluginmanager.py @@ -1,5 +1,5 @@ """ -handling py.test plugins. +managing loading and interacting with pytest plugins. """ import py from py.__.test.plugin import api @@ -10,11 +10,11 @@ class PluginManager(object): comregistry = py._com.Registry() self.comregistry = comregistry self.MultiCall = self.comregistry.MultiCall - self.plugins = {} + self.impname2plugin = {} self.api = py._com.PluginAPI( apiclass=api.PluginHooks, - plugins=self.comregistry) + registry=self.comregistry) def register(self, plugin): self.comregistry.register(plugin) @@ -24,13 +24,13 @@ class PluginManager(object): return self.comregistry.isregistered(plugin) def getplugins(self): - return self.comregistry.plugins + return list(self.comregistry) # API for bootstrapping # def getplugin(self, importname): impname, clsname = canonical_names(importname) - return self.plugins[impname] + return self.impname2plugin[impname] def _envlist(self, varname): val = py.std.os.environ.get(varname, None) @@ -44,8 +44,8 @@ class PluginManager(object): def consider_conftest(self, conftestmodule): cls = getattr(conftestmodule, 'ConftestPlugin', None) - if cls is not None and cls not in self.plugins: - self.plugins[cls] = True + if cls is not None and cls not in self.impname2plugin: + self.impname2plugin[cls] = True self.register(cls()) self.consider_module(conftestmodule) @@ -60,11 +60,11 @@ class PluginManager(object): def import_plugin(self, spec): assert isinstance(spec, str) modname, clsname = canonical_names(spec) - if modname in self.plugins: + if modname in self.impname2plugin: return mod = importplugin(modname) plugin = registerplugin(self.comregistry.register, mod, clsname) - self.plugins[modname] = plugin + self.impname2plugin[modname] = plugin self.consider_module(mod) # # diff --git a/py/test/pycollect.py b/py/test/pycollect.py index b60fcc22c..eac49c3b3 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -386,8 +386,8 @@ class Function(FunctionMixin, py.test.collect.Item): def _raisefuncargerror(self, argname, prefix="pytest_funcarg__"): metainfo = self.repr_metainfo() available = [] - plugins = self.config.pluginmanager.plugins.values() - plugins.extend(self.config.pluginmanager.comregistry.plugins) + plugins = list(self.config.pluginmanager.comregistry) + #plugins.extend(self.config.pluginmanager.registry.plugins) for plugin in plugins: for name in vars(plugin.__class__): if name.startswith(prefix):