- some more adaptation to most recent pluggy API

- avoid using pluggin underscore api
- show pluggy version in header

--HG--
branch : pluggy1
This commit is contained in:
holger krekel 2015-05-05 21:53:04 +02:00
parent a4f2236b36
commit 23538bcd31
8 changed files with 46 additions and 36 deletions

View File

@ -9,10 +9,10 @@ import py
# DON't import pytest here because it causes import cycle troubles
import sys, os
from _pytest import hookspec # the extension point definitions
from pluggy import PluginManager, Hookimpl, Hookspec
from pluggy import PluginManager, HookimplDecorator, HookspecDecorator
hookimpl_opts = Hookimpl("pytest")
hookspec_opts = Hookspec("pytest")
hookimpl_opts = HookimplDecorator("pytest")
hookspec_opts = HookspecDecorator("pytest")
# pytest startup
#
@ -112,7 +112,7 @@ def exclude_pytest_names(name):
class PytestPluginManager(PluginManager):
def __init__(self):
super(PytestPluginManager, self).__init__("pytest")
super(PytestPluginManager, self).__init__("pytest", implprefix="pytest_")
self._warnings = []
self._conftest_plugins = set()
@ -121,7 +121,7 @@ class PytestPluginManager(PluginManager):
self._conftestpath2mod = {}
self._confcutdir = None
self.addhooks(hookspec)
self.add_hookspecs(hookspec)
self.register(self)
if os.environ.get('PYTEST_DEBUG'):
err = sys.stderr
@ -133,26 +133,33 @@ class PytestPluginManager(PluginManager):
self.trace.root.setwriter(err.write)
self.enable_tracing()
def parse_hookimpl_opts(self, method):
opts = super(PytestPluginManager, self).parse_hookimpl_opts(method)
if opts is None:
name = getattr(method, "__name__", None)
if name is not None:
if name.startswith("pytest_") and not exclude_pytest_names(name):
opts = {}
opts["tryfirst"] = hasattr(method, "tryfirst")
opts["trylast"] = hasattr(method, "trylast")
opts["optionalhook"] = hasattr(method, "optionalhook")
opts["hookwrapper"] = hasattr(method, "hookwrapper")
def addhooks(self, module_or_class):
warning = dict(code="I2",
fslocation=py.code.getfslineno(sys._getframe(1)),
message="use pluginmanager.add_hookspecs instead of "
"deprecated addhooks() method.")
self._warnings.append(warning)
return self.add_hookspecs(module_or_class)
def parse_hookimpl_opts(self, plugin, name):
if exclude_pytest_names(name):
return None
method = getattr(plugin, name)
opts = super(PytestPluginManager, self).parse_hookimpl_opts(plugin, name)
if opts is not None:
for name in ("tryfirst", "trylast", "optionalhook", "hookwrapper"):
opts.setdefault(name, hasattr(method, name))
return opts
def parse_hookspec_opts(self, module_or_class, name):
opts = super(PytestPluginManager, self).parse_hookspec_opts(module_or_class, name)
opts = super(PytestPluginManager, self).parse_hookspec_opts(
module_or_class, name)
if opts is None:
method = getattr(module_or_class, name)
if name.startswith("pytest_"):
meth = getattr(module_or_class, name)
opts = {"firstresult": hasattr(meth, "firstresult"),
"historic": hasattr(meth, "historic")}
opts = {"firstresult": hasattr(method, "firstresult"),
"historic": hasattr(method, "historic")}
return opts
def _verify_hook(self, hook, hookmethod):

View File

@ -4,8 +4,6 @@ import sys
import pkgutil
import py
import pluggy
import _pytest

View File

@ -96,10 +96,10 @@ conftest_options = [
def getpluginversioninfo(config):
lines = []
plugininfo = config.pluginmanager._plugin_distinfo
plugininfo = config.pluginmanager.list_plugin_distinfo()
if plugininfo:
lines.append("setuptools registered plugins:")
for dist, plugin in plugininfo:
for plugin, dist in plugininfo:
loc = getattr(plugin, '__file__', repr(plugin))
content = "%s-%s at %s" % (dist.project_name, dist.version, loc)
lines.append(" " + content)
@ -117,7 +117,7 @@ def pytest_report_header(config):
if config.option.traceconfig:
lines.append("active plugins:")
items = config.pluginmanager._name2plugin.items()
items = config.pluginmanager.list_name_plugin()
for name, plugin in items:
if hasattr(plugin, '__file__'):
r = plugin.__file__

View File

@ -1,8 +1,8 @@
""" hook specifications for pytest plugins, invoked from main.py and builtin plugins. """
from pluggy import Hookspec
from pluggy import HookspecDecorator
hookspec_opts = Hookspec("pytest")
hookspec_opts = HookspecDecorator("pytest")
# -------------------------------------------------------------------------
# Initialization hooks called for every plugin

View File

@ -3,6 +3,7 @@
This is a good source for looking at the various reporting hooks.
"""
import pytest
import pluggy
import py
import sys
import time
@ -278,7 +279,8 @@ class TerminalReporter:
if hasattr(sys, 'pypy_version_info'):
verinfo = ".".join(map(str, sys.pypy_version_info[:3]))
msg += "[pypy-%s-%s]" % (verinfo, sys.pypy_version_info[3])
msg += " -- py-%s -- pytest-%s" % (py.__version__, pytest.__version__)
msg += ", pytest-%s, py-%s, pluggy-%s" % (
pytest.__version__, py.__version__, pluggy.__version__)
if self.verbosity > 0 or self.config.option.debug or \
getattr(self.config.option, 'pastebin', None):
msg += " -- " + str(sys.executable)
@ -294,10 +296,11 @@ class TerminalReporter:
if config.inifile:
inifile = config.rootdir.bestrelpath(config.inifile)
lines = ["rootdir: %s, inifile: %s" %(config.rootdir, inifile)]
plugininfo = config.pluginmanager._plugin_distinfo
plugininfo = config.pluginmanager.list_plugin_distinfo()
if plugininfo:
l = []
for dist, plugin in plugininfo:
for plugin, dist in plugininfo:
name = dist.project_name
if name.startswith("pytest-"):
name = name[7:]

View File

@ -48,7 +48,7 @@ def has_environment_marker_support():
def main():
install_requires = ['py>=1.4.27.dev2', 'pluggy>=0.1.0,<0.2.0']
install_requires = ['py>=1.4.27.dev2', 'pluggy>=0.1.0,<1.0.0']
extras_require = {}
if has_environment_marker_support():
extras_require[':python_version=="2.6" or python_version=="3.0" or python_version=="3.1"'] = ['argparse']

View File

@ -7,7 +7,7 @@ def test_version(testdir, pytestconfig):
result.stderr.fnmatch_lines([
'*pytest*%s*imported from*' % (pytest.__version__, )
])
if pytestconfig.pluginmanager._plugin_distinfo:
if pytestconfig.pluginmanager.list_plugin_distinfo():
result.stderr.fnmatch_lines([
"*setuptools registered plugins:",
"*at*",

View File

@ -1,7 +1,9 @@
"""
terminal reporting of the full testing process.
"""
import pytest, py
import pytest
import py
import pluggy
import sys
from _pytest.terminal import TerminalReporter, repr_pythonversion, getreportopt
@ -408,13 +410,13 @@ class TestTerminalFunctional:
verinfo = ".".join(map(str, py.std.sys.version_info[:3]))
result.stdout.fnmatch_lines([
"*===== test session starts ====*",
"platform %s -- Python %s* -- py-%s -- pytest-%s" % (
"platform %s -- Python %s*pytest-%s*py-%s*pluggy-%s" % (
py.std.sys.platform, verinfo,
py.__version__, pytest.__version__),
pytest.__version__, py.__version__, pluggy.__version__),
"*test_header_trailer_info.py .",
"=* 1 passed*in *.[0-9][0-9] seconds *=",
])
if pytest.config.pluginmanager._plugin_distinfo:
if pytest.config.pluginmanager.list_plugin_distinfo():
result.stdout.fnmatch_lines([
"plugins: *",
])