adapt pytest to pluggy's decoratorclass branch

--HG--
branch : pluggy1
This commit is contained in:
holger krekel 2015-04-29 16:40:52 +02:00
parent 5ee7ee0850
commit 25963e0544
6 changed files with 43 additions and 17 deletions

View File

@ -9,7 +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_opts, varnames from pluggy import PluginManager, Hookimpl, Hookspec
hookimpl_opts = Hookimpl("pytest")
hookspec_opts = Hookspec("pytest")
# pytest startup # pytest startup
# #
@ -106,10 +109,10 @@ def exclude_pytest_names(name):
name.startswith("pytest_funcarg__") name.startswith("pytest_funcarg__")
class PytestPluginManager(PluginManager): class PytestPluginManager(PluginManager):
def __init__(self): def __init__(self):
super(PytestPluginManager, self).__init__(prefix="pytest_", super(PytestPluginManager, self).__init__("pytest")
excludefunc=exclude_pytest_names)
self._warnings = [] self._warnings = []
self._conftest_plugins = set() self._conftest_plugins = set()
@ -130,12 +133,31 @@ class PytestPluginManager(PluginManager):
self.trace.root.setwriter(err.write) self.trace.root.setwriter(err.write)
self.enable_tracing() self.enable_tracing()
def get_hookimpl_opts(self, plugin, name):
method = getattr(plugin, name)
opts = super(PytestPluginManager, self).get_hookimpl_opts(plugin, name)
if opts is 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")
return opts
def _verify_hook(self, hook, plugin): def get_hookspec_opts(self, module_or_class, name):
super(PytestPluginManager, self)._verify_hook(hook, plugin) opts = super(PytestPluginManager, self).get_hookspec_opts(module_or_class, name)
method = getattr(plugin, hook.name) if opts is None:
if "__multicall__" in varnames(method): if name.startswith("pytest_"):
fslineno = py.code.getfslineno(method) meth = getattr(module_or_class, name)
opts = {"firstresult": hasattr(meth, "firstresult"),
"historic": hasattr(meth, "historic")}
return opts
def _verify_hook(self, hook, hookmethod):
super(PytestPluginManager, self)._verify_hook(hook, hookmethod)
if "__multicall__" in hookmethod.argnames:
fslineno = py.code.getfslineno(hookmethod.function)
warning = dict(code="I1", warning = dict(code="I1",
fslocation=fslineno, fslocation=fslineno,
message="%r hook uses deprecated __multicall__ " message="%r hook uses deprecated __multicall__ "

View File

@ -70,7 +70,7 @@ def pytest_cmdline_main(config):
genscript = config.getvalue("genscript") genscript = config.getvalue("genscript")
if genscript: if genscript:
tw = py.io.TerminalWriter() tw = py.io.TerminalWriter()
deps = ['py', '_pytest', 'pytest', 'pluggy'] deps = ['py', 'pluggy', '_pytest', 'pytest']
if sys.version_info < (2,7): if sys.version_info < (2,7):
deps.append("argparse") deps.append("argparse")
tw.line("generated script will run on python2.6-python3.3++") tw.line("generated script will run on python2.6-python3.3++")

View File

@ -1,6 +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_opts from pluggy import Hookspec
hookspec_opts = Hookspec("pytest")
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# Initialization hooks called for every plugin # Initialization hooks called for every plugin

View File

@ -501,13 +501,13 @@ class Session(FSCollector):
def __init__(self, config): def __init__(self, config):
FSCollector.__init__(self, config.rootdir, parent=None, FSCollector.__init__(self, config.rootdir, parent=None,
config=config, session=self) config=config, session=self)
self.config.pluginmanager.register(self, name="session") self._fs2hookproxy = {}
self._testsfailed = 0 self._testsfailed = 0
self.shouldstop = False self.shouldstop = False
self.trace = config.trace.root.get("collection") self.trace = config.trace.root.get("collection")
self._norecursepatterns = config.getini("norecursedirs") self._norecursepatterns = config.getini("norecursedirs")
self.startdir = py.path.local() self.startdir = py.path.local()
self._fs2hookproxy = {} self.config.pluginmanager.register(self, name="session")
def _makeid(self): def _makeid(self):
return "" return ""

View File

@ -11,8 +11,10 @@ if __name__ == '__main__': # if run as a script or by 'python -m pytest'
# else we are imported # else we are imported
from _pytest.config import main, UsageError, _preloadplugins, cmdline from _pytest.config import (
from pluggy import hookspec_opts, hookimpl_opts main, UsageError, _preloadplugins, cmdline,
hookspec_opts, hookimpl_opts
)
from _pytest import __version__ from _pytest import __version__
_preloadplugins() # to populate pytest.* namespace so help(pytest) works _preloadplugins() # to populate pytest.* namespace so help(pytest) works

View File

@ -357,9 +357,9 @@ def test_load_initial_conftest_last_ordering(testdir):
pm.register(m) pm.register(m)
hc = pm.hook.pytest_load_initial_conftests hc = pm.hook.pytest_load_initial_conftests
l = hc._nonwrappers + hc._wrappers l = hc._nonwrappers + hc._wrappers
assert l[-1].__module__ == "_pytest.capture" assert l[-1].function.__module__ == "_pytest.capture"
assert l[-2] == m.pytest_load_initial_conftests assert l[-2].function == m.pytest_load_initial_conftests
assert l[-3].__module__ == "_pytest.config" assert l[-3].function.__module__ == "_pytest.config"
class TestWarning: class TestWarning:
def test_warn_config(self, testdir): def test_warn_config(self, testdir):