move bookkeeping of conftest plugins in core pluginmanager to PytestPluginManager

--HG--
branch : plugin_no_pytest
This commit is contained in:
holger krekel 2015-04-22 13:33:01 +02:00
parent 7049ebe4e2
commit c08dfdc330
2 changed files with 22 additions and 15 deletions

View File

@ -97,6 +97,7 @@ class PytestPluginManager(PluginManager):
excludefunc=exclude_pytest_names)
self._warnings = []
self._plugin_distinfo = []
self._globalplugins = []
self.addhooks(hookspec)
self.register(self)
if os.environ.get('PYTEST_DEBUG'):
@ -108,6 +109,19 @@ class PytestPluginManager(PluginManager):
pass
self.set_tracing(err.write)
def register(self, plugin, name=None, conftest=False):
ret = super(PytestPluginManager, self).register(plugin, name)
if ret and not conftest:
self._globalplugins.append(plugin)
return ret
def unregister(self, plugin):
super(PytestPluginManager, self).unregister(plugin)
try:
self._globalplugins.remove(plugin)
except ValueError:
pass
def getplugin(self, name):
if name is None:
return name
@ -787,7 +801,7 @@ class Config(object):
setattr(self.option, opt.dest, opt.default)
def _getmatchingplugins(self, fspath):
return self.pluginmanager._plugins + \
return self.pluginmanager._globalplugins + \
self._conftest.getconftestmodules(fspath)
def pytest_load_initial_conftests(self, early_config):

View File

@ -140,7 +140,6 @@ class PluginManager(object):
self._excludefunc = excludefunc
self._name2plugin = {}
self._plugins = []
self._conftestplugins = []
self._plugin2hookcallers = {}
self.trace = TagTracer().get("pluginmanage")
self._shutdown = []
@ -205,7 +204,7 @@ class PluginManager(object):
", ".join(hook.argnames))
yield hook
def register(self, plugin, name=None, conftest=False):
def register(self, plugin, name=None):
if self._name2plugin.get(name, None) == -1:
return
name = name or getattr(plugin, '__name__', str(id(plugin)))
@ -219,9 +218,6 @@ class PluginManager(object):
hookcallers = list(self._scan_plugin(plugin))
self._plugin2hookcallers[plugin] = hookcallers
self._name2plugin[name] = plugin
if conftest:
self._conftestplugins.append(plugin)
else:
self._plugins.append(plugin)
# finally make sure that the methods of the new plugin take part
for hookcaller in hookcallers:
@ -229,10 +225,7 @@ class PluginManager(object):
return True
def unregister(self, plugin):
try:
self._plugins.remove(plugin)
except KeyError:
self._conftestplugins.remove(plugin)
for name, value in list(self._name2plugin.items()):
if value == plugin:
del self._name2plugin[name]
@ -247,13 +240,13 @@ class PluginManager(object):
while self._shutdown:
func = self._shutdown.pop()
func()
self._plugins = self._conftestplugins = []
self._plugins = []
self._name2plugin.clear()
def isregistered(self, plugin, name=None):
if self.getplugin(name) is not None:
return True
return plugin in self._plugins or plugin in self._conftestplugins
return plugin in self._plugins
def addhooks(self, module_or_class):
isclass = int(inspect.isclass(module_or_class))
@ -271,7 +264,7 @@ class PluginManager(object):
%(self._prefix, module_or_class))
def getplugins(self):
return self._plugins + self._conftestplugins
return self._plugins
def hasplugin(self, name):
return bool(self.getplugin(name))
@ -281,7 +274,7 @@ class PluginManager(object):
def listattr(self, attrname, plugins=None):
if plugins is None:
plugins = self._plugins + self._conftestplugins
plugins = self._plugins
l = []
last = []
wrappers = []