Skip to content

Commit

Permalink
- some more adaptation to most recent pluggy API
Browse files Browse the repository at this point in the history
- avoid using pluggin underscore api
- show pluggy version in header

--HG--
branch : pluggy1
  • Loading branch information
hpk42 committed May 5, 2015
1 parent a4f2236 commit 23538bc
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
47 changes: 27 additions & 20 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
# 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
#
Expand Down Expand Up @@ -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()

Expand All @@ -121,7 +121,7 @@ def __init__(self):
self._conftestpath2mod = {}
self._confcutdir = None

self.addhooks(hookspec)
self.add_hookspecs(hookspec)
self.register(self)
if os.environ.get('PYTEST_DEBUG'):
err = sys.stderr
Expand All @@ -133,26 +133,33 @@ def __init__(self):
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):
Expand Down
2 changes: 0 additions & 2 deletions _pytest/genscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import pkgutil

import py
import pluggy

import _pytest


Expand Down
6 changes: 3 additions & 3 deletions _pytest/helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ def showhelp(config):

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)
Expand All @@ -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__
Expand Down
4 changes: 2 additions & 2 deletions _pytest/hookspec.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 6 additions & 3 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -278,7 +279,8 @@ def pytest_sessionstart(self, session):
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)
Expand All @@ -294,10 +296,11 @@ def pytest_report_header(self, config):
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:]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion testing/test_helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*",
Expand Down
10 changes: 6 additions & 4 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -408,13 +410,13 @@ def test_passes():
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: *",
])
Expand Down

0 comments on commit 23538bc

Please sign in to comment.