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

View File

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

View File

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

View File

@ -1,8 +1,8 @@
""" hook specifications for pytest plugins, invoked from main.py and builtin plugins. """ """ 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 # Initialization hooks called for every plugin

View File

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

View File

@ -48,7 +48,7 @@ def has_environment_marker_support():
def main(): 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 = {} extras_require = {}
if has_environment_marker_support(): if has_environment_marker_support():
extras_require[':python_version=="2.6" or python_version=="3.0" or python_version=="3.1"'] = ['argparse'] 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([ result.stderr.fnmatch_lines([
'*pytest*%s*imported from*' % (pytest.__version__, ) '*pytest*%s*imported from*' % (pytest.__version__, )
]) ])
if pytestconfig.pluginmanager._plugin_distinfo: if pytestconfig.pluginmanager.list_plugin_distinfo():
result.stderr.fnmatch_lines([ result.stderr.fnmatch_lines([
"*setuptools registered plugins:", "*setuptools registered plugins:",
"*at*", "*at*",

View File

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