diff --git a/_pytest/config.py b/_pytest/config.py index 04cb09a4c..1f68742eb 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -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): diff --git a/_pytest/genscript.py b/_pytest/genscript.py index 33b844a69..fb2ca04cd 100755 --- a/_pytest/genscript.py +++ b/_pytest/genscript.py @@ -4,8 +4,6 @@ import sys import pkgutil import py -import pluggy - import _pytest diff --git a/_pytest/helpconfig.py b/_pytest/helpconfig.py index 72fae555f..edbb9159b 100644 --- a/_pytest/helpconfig.py +++ b/_pytest/helpconfig.py @@ -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__ diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index 938a8bb7f..606ff3108 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -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 diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 03c539b85..cca947bb7 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -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:] diff --git a/setup.py b/setup.py index 909c0957e..3a4fd391f 100644 --- a/setup.py +++ b/setup.py @@ -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'] diff --git a/testing/test_helpconfig.py b/testing/test_helpconfig.py index bee4d6ede..10041aa78 100644 --- a/testing/test_helpconfig.py +++ b/testing/test_helpconfig.py @@ -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*", diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 61fca0b59..cf2a69cb9 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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: *", ])