rename "api" into "hook" in most places.
--HG-- branch : trunk
This commit is contained in:
parent
1f14aacbc2
commit
8182d341a5
|
@ -57,7 +57,7 @@ initpkg(__name__,
|
||||||
'_com.Registry' : ('./_com.py', 'Registry'),
|
'_com.Registry' : ('./_com.py', 'Registry'),
|
||||||
'_com.MultiCall' : ('./_com.py', 'MultiCall'),
|
'_com.MultiCall' : ('./_com.py', 'MultiCall'),
|
||||||
'_com.comregistry' : ('./_com.py', 'comregistry'),
|
'_com.comregistry' : ('./_com.py', 'comregistry'),
|
||||||
'_com.PluginAPI' : ('./_com.py', 'PluginAPI'),
|
'_com.Hooks' : ('./_com.py', 'Hooks'),
|
||||||
|
|
||||||
# py lib cmdline tools
|
# py lib cmdline tools
|
||||||
'cmdline.pytest' : ('./cmdline/pytest.py', 'main',),
|
'cmdline.pytest' : ('./cmdline/pytest.py', 'main',),
|
||||||
|
@ -146,7 +146,7 @@ initpkg(__name__,
|
||||||
|
|
||||||
# gateways into remote contexts
|
# gateways into remote contexts
|
||||||
'execnet.__doc__' : ('./execnet/__init__.py', '__doc__'),
|
'execnet.__doc__' : ('./execnet/__init__.py', '__doc__'),
|
||||||
'execnet._API' : ('./execnet/gateway.py', 'ExecnetAPI'),
|
'execnet._HookSpecs' : ('./execnet/gateway.py', 'ExecnetAPI'),
|
||||||
'execnet.SocketGateway' : ('./execnet/register.py', 'SocketGateway'),
|
'execnet.SocketGateway' : ('./execnet/register.py', 'SocketGateway'),
|
||||||
'execnet.PopenGateway' : ('./execnet/register.py', 'PopenGateway'),
|
'execnet.PopenGateway' : ('./execnet/register.py', 'PopenGateway'),
|
||||||
'execnet.SshGateway' : ('./execnet/register.py', 'SshGateway'),
|
'execnet.SshGateway' : ('./execnet/register.py', 'SshGateway'),
|
||||||
|
|
16
py/_com.py
16
py/_com.py
|
@ -108,21 +108,21 @@ class Registry:
|
||||||
*args, **kwargs).execute(firstresult=True)
|
*args, **kwargs).execute(firstresult=True)
|
||||||
|
|
||||||
|
|
||||||
class PluginAPI:
|
class Hooks:
|
||||||
def __init__(self, apiclass, registry=None):
|
def __init__(self, hookspecs, registry=None):
|
||||||
self._apiclass = apiclass
|
self._hookspecs = hookspecs
|
||||||
if registry is None:
|
if registry is None:
|
||||||
registry = comregistry
|
registry = comregistry
|
||||||
self.registry = registry
|
self.registry = registry
|
||||||
for name, method in vars(apiclass).items():
|
for name, method in vars(hookspecs).items():
|
||||||
if name[:2] != "__":
|
if name[:2] != "__":
|
||||||
firstresult = getattr(method, 'firstresult', False)
|
firstresult = getattr(method, 'firstresult', False)
|
||||||
mm = ApiCall(registry, name, firstresult=firstresult)
|
mm = HookCall(registry, name, firstresult=firstresult)
|
||||||
setattr(self, name, mm)
|
setattr(self, name, mm)
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<PluginAPI %r %r>" %(self._apiclass, self._plugins)
|
return "<Hooks %r %r>" %(self._hookspecs, self._plugins)
|
||||||
|
|
||||||
class ApiCall:
|
class HookCall:
|
||||||
def __init__(self, registry, name, firstresult):
|
def __init__(self, registry, name, firstresult):
|
||||||
self.registry = registry
|
self.registry = registry
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -130,7 +130,7 @@ class ApiCall:
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
mode = self.firstresult and "firstresult" or "each"
|
mode = self.firstresult and "firstresult" or "each"
|
||||||
return "<ApiCall %r mode=%s %s>" %(self.name, mode, self.registry)
|
return "<HookCall %r mode=%s %s>" %(self.name, mode, self.registry)
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
if args:
|
if args:
|
||||||
|
|
|
@ -88,10 +88,10 @@ class Gateway(object):
|
||||||
self._channelfactory = ChannelFactory(self, _startcount)
|
self._channelfactory = ChannelFactory(self, _startcount)
|
||||||
self._cleanup.register(self)
|
self._cleanup.register(self)
|
||||||
if _startcount == 1: # only import 'py' on the "client" side
|
if _startcount == 1: # only import 'py' on the "client" side
|
||||||
from py._com import PluginAPI
|
from py._com import Hooks
|
||||||
self.api = PluginAPI(ExecnetAPI)
|
self.hook = Hooks(ExecnetAPI)
|
||||||
else:
|
else:
|
||||||
self.api = ExecnetAPI()
|
self.hook = ExecnetAPI()
|
||||||
|
|
||||||
def _initreceive(self, requestqueue=False):
|
def _initreceive(self, requestqueue=False):
|
||||||
if requestqueue:
|
if requestqueue:
|
||||||
|
@ -353,7 +353,7 @@ class Gateway(object):
|
||||||
self._cleanup.unregister(self)
|
self._cleanup.unregister(self)
|
||||||
self._stopexec()
|
self._stopexec()
|
||||||
self._stopsend()
|
self._stopsend()
|
||||||
self.api.pyexecnet_gateway_exit(gateway=self)
|
self.hook.pyexecnet_gateway_exit(gateway=self)
|
||||||
|
|
||||||
def _remote_redirect(self, stdout=None, stderr=None):
|
def _remote_redirect(self, stdout=None, stderr=None):
|
||||||
""" return a handle representing a redirection of a remote
|
""" return a handle representing a redirection of a remote
|
||||||
|
|
|
@ -21,7 +21,7 @@ class GatewayManager:
|
||||||
if not spec.chdir and not spec.popen:
|
if not spec.chdir and not spec.popen:
|
||||||
spec.chdir = defaultchdir
|
spec.chdir = defaultchdir
|
||||||
self.specs.append(spec)
|
self.specs.append(spec)
|
||||||
self.api = py._com.PluginAPI(py.execnet._API)
|
self.hook = py._com.Hooks(py.execnet._HookSpecs)
|
||||||
|
|
||||||
def makegateways(self):
|
def makegateways(self):
|
||||||
assert not self.gateways
|
assert not self.gateways
|
||||||
|
@ -29,7 +29,7 @@ class GatewayManager:
|
||||||
gw = py.execnet.makegateway(spec)
|
gw = py.execnet.makegateway(spec)
|
||||||
self.gateways.append(gw)
|
self.gateways.append(gw)
|
||||||
gw.id = "[%s]" % len(self.gateways)
|
gw.id = "[%s]" % len(self.gateways)
|
||||||
self.api.pyexecnet_gwmanage_newgateway(
|
self.hook.pyexecnet_gwmanage_newgateway(
|
||||||
gateway=gw, platinfo=gw._rinfo())
|
gateway=gw, platinfo=gw._rinfo())
|
||||||
|
|
||||||
def getgateways(self, remote=True, inplacelocal=True):
|
def getgateways(self, remote=True, inplacelocal=True):
|
||||||
|
@ -75,12 +75,12 @@ class GatewayManager:
|
||||||
rsync.add_target_host(gateway, finished=finished)
|
rsync.add_target_host(gateway, finished=finished)
|
||||||
seen[spec] = gateway
|
seen[spec] = gateway
|
||||||
if seen:
|
if seen:
|
||||||
self.api.pyexecnet_gwmanage_rsyncstart(
|
self.hook.pyexecnet_gwmanage_rsyncstart(
|
||||||
source=source,
|
source=source,
|
||||||
gateways=seen.values(),
|
gateways=seen.values(),
|
||||||
)
|
)
|
||||||
rsync.send()
|
rsync.send()
|
||||||
self.api.pyexecnet_gwmanage_rsyncfinish(
|
self.hook.pyexecnet_gwmanage_rsyncfinish(
|
||||||
source=source,
|
source=source,
|
||||||
gateways=seen.values()
|
gateways=seen.values()
|
||||||
)
|
)
|
||||||
|
|
|
@ -40,7 +40,7 @@ class InstallableGateway(gateway.Gateway):
|
||||||
super(InstallableGateway, self).__init__(io=io, _startcount=1)
|
super(InstallableGateway, self).__init__(io=io, _startcount=1)
|
||||||
# XXX we dissallow execution form the other side
|
# XXX we dissallow execution form the other side
|
||||||
self._initreceive(requestqueue=False)
|
self._initreceive(requestqueue=False)
|
||||||
self.api.pyexecnet_gateway_init(gateway=self)
|
self.hook.pyexecnet_gateway_init(gateway=self)
|
||||||
|
|
||||||
def _remote_bootstrap_gateway(self, io, extra=''):
|
def _remote_bootstrap_gateway(self, io, extra=''):
|
||||||
""" return Gateway with a asynchronously remotely
|
""" return Gateway with a asynchronously remotely
|
||||||
|
|
|
@ -21,7 +21,7 @@ class TestGatewayManagerPopen:
|
||||||
assert spec.chdir == "abc"
|
assert spec.chdir == "abc"
|
||||||
|
|
||||||
def test_popen_makegateway_events(self, _pytest):
|
def test_popen_makegateway_events(self, _pytest):
|
||||||
rec = _pytest.getcallrecorder(py.execnet._API)
|
rec = _pytest.getcallrecorder(py.execnet._HookSpecs)
|
||||||
hm = GatewayManager(["popen"] * 2)
|
hm = GatewayManager(["popen"] * 2)
|
||||||
hm.makegateways()
|
hm.makegateways()
|
||||||
call = rec.popcall("pyexecnet_gwmanage_newgateway")
|
call = rec.popcall("pyexecnet_gwmanage_newgateway")
|
||||||
|
@ -63,7 +63,7 @@ class TestGatewayManagerPopen:
|
||||||
|
|
||||||
def test_hostmanage_rsync_same_popen_twice(self, mysetup, _pytest):
|
def test_hostmanage_rsync_same_popen_twice(self, mysetup, _pytest):
|
||||||
source, dest = mysetup.source, mysetup.dest
|
source, dest = mysetup.source, mysetup.dest
|
||||||
rec = _pytest.getcallrecorder(py.execnet._API)
|
rec = _pytest.getcallrecorder(py.execnet._HookSpecs)
|
||||||
hm = GatewayManager(["popen//chdir=%s" %dest] * 2)
|
hm = GatewayManager(["popen//chdir=%s" %dest] * 2)
|
||||||
hm.makegateways()
|
hm.makegateways()
|
||||||
source.ensure("dir1", "dir2", "hello")
|
source.ensure("dir1", "dir2", "hello")
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import py
|
import py
|
||||||
import os
|
import os
|
||||||
from py._com import Registry, MultiCall
|
from py._com import Registry, MultiCall
|
||||||
from py._com import PluginAPI
|
from py._com import Hooks
|
||||||
|
|
||||||
pytest_plugins = "xfail"
|
pytest_plugins = "xfail"
|
||||||
|
|
||||||
|
@ -144,14 +144,14 @@ class TestRegistry:
|
||||||
def test_api_and_defaults():
|
def test_api_and_defaults():
|
||||||
assert isinstance(py._com.comregistry, Registry)
|
assert isinstance(py._com.comregistry, Registry)
|
||||||
|
|
||||||
class TestPluginAPI:
|
class TestHooks:
|
||||||
def test_happypath(self):
|
def test_happypath(self):
|
||||||
registry = Registry()
|
registry = Registry()
|
||||||
class Api:
|
class Api:
|
||||||
def hello(self, arg):
|
def hello(self, arg):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
mcm = PluginAPI(apiclass=Api, registry=registry)
|
mcm = Hooks(hookspecs=Api, registry=registry)
|
||||||
assert hasattr(mcm, 'hello')
|
assert hasattr(mcm, 'hello')
|
||||||
assert repr(mcm.hello).find("hello") != -1
|
assert repr(mcm.hello).find("hello") != -1
|
||||||
class Plugin:
|
class Plugin:
|
||||||
|
@ -167,7 +167,7 @@ class TestPluginAPI:
|
||||||
class Api:
|
class Api:
|
||||||
def hello(self, arg):
|
def hello(self, arg):
|
||||||
pass
|
pass
|
||||||
mcm = PluginAPI(apiclass=Api, registry=registry)
|
mcm = Hooks(hookspecs=Api, registry=registry)
|
||||||
excinfo = py.test.raises(TypeError, "mcm.hello(3)")
|
excinfo = py.test.raises(TypeError, "mcm.hello(3)")
|
||||||
assert str(excinfo.value).find("only keyword arguments") != -1
|
assert str(excinfo.value).find("only keyword arguments") != -1
|
||||||
assert str(excinfo.value).find("hello(self, arg)")
|
assert str(excinfo.value).find("hello(self, arg)")
|
||||||
|
@ -178,7 +178,7 @@ class TestPluginAPI:
|
||||||
def hello(self, arg): pass
|
def hello(self, arg): pass
|
||||||
hello.firstresult = True
|
hello.firstresult = True
|
||||||
|
|
||||||
mcm = PluginAPI(apiclass=Api, registry=registry)
|
mcm = Hooks(hookspecs=Api, registry=registry)
|
||||||
class Plugin:
|
class Plugin:
|
||||||
def hello(self, arg):
|
def hello(self, arg):
|
||||||
return arg + 1
|
return arg + 1
|
||||||
|
@ -188,5 +188,5 @@ class TestPluginAPI:
|
||||||
|
|
||||||
def test_default_plugins(self):
|
def test_default_plugins(self):
|
||||||
class Api: pass
|
class Api: pass
|
||||||
mcm = PluginAPI(apiclass=Api)
|
mcm = Hooks(hookspecs=Api)
|
||||||
assert mcm.registry == py._com.comregistry
|
assert mcm.registry == py._com.comregistry
|
||||||
|
|
|
@ -409,14 +409,14 @@ class Directory(FSCollector):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def consider_file(self, path):
|
def consider_file(self, path):
|
||||||
return self.config.api.pytest_collect_file(path=path, parent=self)
|
return self.config.hook.pytest_collect_file(path=path, parent=self)
|
||||||
|
|
||||||
def consider_dir(self, path, usefilters=None):
|
def consider_dir(self, path, usefilters=None):
|
||||||
if usefilters is not None:
|
if usefilters is not None:
|
||||||
py.log._apiwarn("0.99", "usefilters argument not needed")
|
py.log._apiwarn("0.99", "usefilters argument not needed")
|
||||||
res = self.config.api.pytest_collect_recurse(path=path, parent=self)
|
res = self.config.hook.pytest_collect_recurse(path=path, parent=self)
|
||||||
if res is None or res:
|
if res is None or res:
|
||||||
return self.config.api.pytest_collect_directory(
|
return self.config.hook.pytest_collect_directory(
|
||||||
path=path, parent=self)
|
path=path, parent=self)
|
||||||
|
|
||||||
class Item(Node):
|
class Item(Node):
|
||||||
|
|
|
@ -42,7 +42,7 @@ class Config(object):
|
||||||
self.pluginmanager = pluginmanager
|
self.pluginmanager = pluginmanager
|
||||||
self._conftest = Conftest(onimport=self._onimportconftest)
|
self._conftest = Conftest(onimport=self._onimportconftest)
|
||||||
self._setupstate = SetupState()
|
self._setupstate = SetupState()
|
||||||
self.api = pluginmanager.api
|
self.hook = pluginmanager.hook
|
||||||
|
|
||||||
def _onimportconftest(self, conftestmodule):
|
def _onimportconftest(self, conftestmodule):
|
||||||
self.trace("loaded conftestmodule %r" %(conftestmodule,))
|
self.trace("loaded conftestmodule %r" %(conftestmodule,))
|
||||||
|
@ -50,7 +50,7 @@ class Config(object):
|
||||||
|
|
||||||
def trace(self, msg):
|
def trace(self, msg):
|
||||||
if getattr(self.option, 'traceconfig', None):
|
if getattr(self.option, 'traceconfig', None):
|
||||||
self.api.pytest_trace(category="config", msg=msg)
|
self.hook.pytest_trace(category="config", msg=msg)
|
||||||
|
|
||||||
def _processopt(self, opt):
|
def _processopt(self, opt):
|
||||||
if hasattr(opt, 'default') and opt.dest:
|
if hasattr(opt, 'default') and opt.dest:
|
||||||
|
|
|
@ -97,7 +97,7 @@ class DSession(Session):
|
||||||
|
|
||||||
callname, args, kwargs = eventcall
|
callname, args, kwargs = eventcall
|
||||||
if callname is not None:
|
if callname is not None:
|
||||||
call = getattr(self.config.api, callname)
|
call = getattr(self.config.hook, callname)
|
||||||
assert not args
|
assert not args
|
||||||
call(**kwargs)
|
call(**kwargs)
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ class DSession(Session):
|
||||||
# events other than HostDown upstream
|
# events other than HostDown upstream
|
||||||
eventname, args, kwargs = self.queue.get()
|
eventname, args, kwargs = self.queue.get()
|
||||||
if eventname == "pytest_testnodedown":
|
if eventname == "pytest_testnodedown":
|
||||||
self.config.api.pytest_testnodedown(**kwargs)
|
self.config.hook.pytest_testnodedown(**kwargs)
|
||||||
self.removenode(kwargs['node'])
|
self.removenode(kwargs['node'])
|
||||||
if not self.node2pending:
|
if not self.node2pending:
|
||||||
# finished
|
# finished
|
||||||
|
@ -176,7 +176,7 @@ class DSession(Session):
|
||||||
if isinstance(next, py.test.collect.Item):
|
if isinstance(next, py.test.collect.Item):
|
||||||
senditems.append(next)
|
senditems.append(next)
|
||||||
else:
|
else:
|
||||||
self.config.api.pytest_collectstart(collector=next)
|
self.config.hook.pytest_collectstart(collector=next)
|
||||||
self.queueevent("pytest_collectreport", rep=basic_collect_report(next))
|
self.queueevent("pytest_collectreport", rep=basic_collect_report(next))
|
||||||
if self.config.option.dist == "each":
|
if self.config.option.dist == "each":
|
||||||
self.senditems_each(senditems)
|
self.senditems_each(senditems)
|
||||||
|
@ -199,7 +199,7 @@ class DSession(Session):
|
||||||
pending.extend(sending)
|
pending.extend(sending)
|
||||||
for item in sending:
|
for item in sending:
|
||||||
self.item2nodes.setdefault(item, []).append(node)
|
self.item2nodes.setdefault(item, []).append(node)
|
||||||
self.config.api.pytest_itemstart(item=item, node=node)
|
self.config.hook.pytest_itemstart(item=item, node=node)
|
||||||
tosend[:] = tosend[room:] # update inplace
|
tosend[:] = tosend[room:] # update inplace
|
||||||
if tosend:
|
if tosend:
|
||||||
# we have some left, give it to the main loop
|
# we have some left, give it to the main loop
|
||||||
|
@ -218,7 +218,7 @@ class DSession(Session):
|
||||||
# "sending same item %r to multiple "
|
# "sending same item %r to multiple "
|
||||||
# "not implemented" %(item,))
|
# "not implemented" %(item,))
|
||||||
self.item2nodes.setdefault(item, []).append(node)
|
self.item2nodes.setdefault(item, []).append(node)
|
||||||
self.config.api.pytest_itemstart(item=item, node=node)
|
self.config.hook.pytest_itemstart(item=item, node=node)
|
||||||
pending.extend(sending)
|
pending.extend(sending)
|
||||||
tosend[:] = tosend[room:] # update inplace
|
tosend[:] = tosend[room:] # update inplace
|
||||||
if not tosend:
|
if not tosend:
|
||||||
|
@ -241,7 +241,7 @@ class DSession(Session):
|
||||||
longrepr = "!!! Node %r crashed during running of test %r" %(node, item)
|
longrepr = "!!! Node %r crashed during running of test %r" %(node, item)
|
||||||
rep = ItemTestReport(item, when="???", excinfo=longrepr)
|
rep = ItemTestReport(item, when="???", excinfo=longrepr)
|
||||||
rep.node = node
|
rep.node = node
|
||||||
self.config.api.pytest_itemtestreport(rep=rep)
|
self.config.hook.pytest_itemtestreport(rep=rep)
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
""" setup any neccessary resources ahead of the test run. """
|
""" setup any neccessary resources ahead of the test run. """
|
||||||
|
|
|
@ -15,7 +15,7 @@ class NodeManager(object):
|
||||||
self._nodesready = py.std.threading.Event()
|
self._nodesready = py.std.threading.Event()
|
||||||
|
|
||||||
def trace(self, msg):
|
def trace(self, msg):
|
||||||
self.config.api.pytest_trace(category="nodemanage", msg=msg)
|
self.config.hook.pytest_trace(category="nodemanage", msg=msg)
|
||||||
|
|
||||||
def config_getignores(self):
|
def config_getignores(self):
|
||||||
return self.config.getconftest_pathlist("rsyncignore")
|
return self.config.getconftest_pathlist("rsyncignore")
|
||||||
|
|
|
@ -147,7 +147,7 @@ def slave_runsession(channel, config, fullwidth, hasmarkup):
|
||||||
|
|
||||||
DEBUG("SLAVE: starting session.main()")
|
DEBUG("SLAVE: starting session.main()")
|
||||||
session.main(colitems)
|
session.main(colitems)
|
||||||
session.config.api.pytest_looponfailinfo(
|
session.config.hook.pytest_looponfailinfo(
|
||||||
failreports=list(failreports),
|
failreports=list(failreports),
|
||||||
rootdirs=[config.topdir])
|
rootdirs=[config.topdir])
|
||||||
channel.send([x.colitem._totrail() for x in failreports])
|
channel.send([x.colitem._totrail() for x in failreports])
|
||||||
|
|
|
@ -8,11 +8,11 @@ class PytestArg:
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
def getcallrecorder(self, apiclass, comregistry=None):
|
def getcallrecorder(self, hookspecs, comregistry=None):
|
||||||
if comregistry is None:
|
if comregistry is None:
|
||||||
comregistry = self.request.config.pluginmanager.comregistry
|
comregistry = self.request.config.pluginmanager.comregistry
|
||||||
callrecorder = CallRecorder(comregistry)
|
callrecorder = CallRecorder(comregistry)
|
||||||
callrecorder.start_recording(apiclass)
|
callrecorder.start_recording(hookspecs)
|
||||||
self.request.addfinalizer(callrecorder.finalize)
|
self.request.addfinalizer(callrecorder.finalize)
|
||||||
return callrecorder
|
return callrecorder
|
||||||
|
|
||||||
|
@ -35,17 +35,17 @@ class CallRecorder:
|
||||||
self.calls = []
|
self.calls = []
|
||||||
self._recorders = {}
|
self._recorders = {}
|
||||||
|
|
||||||
def start_recording(self, apiclass):
|
def start_recording(self, hookspecs):
|
||||||
assert apiclass not in self._recorders
|
assert hookspecs not in self._recorders
|
||||||
class RecordCalls:
|
class RecordCalls:
|
||||||
_recorder = self
|
_recorder = self
|
||||||
for name, method in vars(apiclass).items():
|
for name, method in vars(hookspecs).items():
|
||||||
if name[0] != "_":
|
if name[0] != "_":
|
||||||
setattr(RecordCalls, name, self._getcallparser(method))
|
setattr(RecordCalls, name, self._getcallparser(method))
|
||||||
recorder = RecordCalls()
|
recorder = RecordCalls()
|
||||||
self._recorders[apiclass] = recorder
|
self._recorders[hookspecs] = recorder
|
||||||
self._comregistry.register(recorder)
|
self._comregistry.register(recorder)
|
||||||
self.api = py._com.PluginAPI(apiclass, registry=self._comregistry)
|
self.hook = py._com.Hooks(hookspecs, registry=self._comregistry)
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
for recorder in self._recorders.values():
|
for recorder in self._recorders.values():
|
||||||
|
@ -53,8 +53,8 @@ class CallRecorder:
|
||||||
self._recorders.clear()
|
self._recorders.clear()
|
||||||
|
|
||||||
def recordsmethod(self, name):
|
def recordsmethod(self, name):
|
||||||
for apiclass in self._recorders:
|
for hookspecs in self._recorders:
|
||||||
if hasattr(apiclass, name):
|
if hasattr(hookspecs, name):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _getcallparser(self, method):
|
def _getcallparser(self, method):
|
||||||
|
@ -97,7 +97,7 @@ class CallRecorder:
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(_pytestPlugin)
|
plugintester.hookcheck(_pytestPlugin)
|
||||||
|
|
||||||
def test_callrecorder_basic():
|
def test_callrecorder_basic():
|
||||||
comregistry = py._com.Registry()
|
comregistry = py._com.Registry()
|
||||||
|
@ -106,7 +106,7 @@ def test_callrecorder_basic():
|
||||||
def xyz(self, arg):
|
def xyz(self, arg):
|
||||||
pass
|
pass
|
||||||
rec.start_recording(ApiClass)
|
rec.start_recording(ApiClass)
|
||||||
rec.api.xyz(arg=123)
|
rec.hook.xyz(arg=123)
|
||||||
call = rec.popcall("xyz")
|
call = rec.popcall("xyz")
|
||||||
assert call.arg == 123
|
assert call.arg == 123
|
||||||
assert call._name == "xyz"
|
assert call._name == "xyz"
|
||||||
|
@ -124,7 +124,7 @@ def test_functional(testdir, linecomp):
|
||||||
def xyz(self, arg):
|
def xyz(self, arg):
|
||||||
return arg + 1
|
return arg + 1
|
||||||
rec._comregistry.register(Plugin())
|
rec._comregistry.register(Plugin())
|
||||||
res = rec.api.xyz(arg=41)
|
res = rec.hook.xyz(arg=41)
|
||||||
assert res == [42]
|
assert res == [42]
|
||||||
""")
|
""")
|
||||||
sorter.assertoutcome(passed=1)
|
sorter.assertoutcome(passed=1)
|
||||||
|
|
|
@ -10,7 +10,7 @@ class DefaultPlugin:
|
||||||
else:
|
else:
|
||||||
runner = basic_run_report
|
runner = basic_run_report
|
||||||
report = runner(item, pdb=pdb)
|
report = runner(item, pdb=pdb)
|
||||||
item.config.api.pytest_itemtestreport(rep=report)
|
item.config.hook.pytest_itemtestreport(rep=report)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def pytest_item_makereport(self, item, excinfo, when, outerr):
|
def pytest_item_makereport(self, item, excinfo, when, outerr):
|
||||||
|
@ -20,7 +20,7 @@ class DefaultPlugin:
|
||||||
def pytest_item_runtest_finished(self, item, excinfo, outerr):
|
def pytest_item_runtest_finished(self, item, excinfo, outerr):
|
||||||
from py.__.test import runner
|
from py.__.test import runner
|
||||||
rep = runner.ItemTestReport(item, excinfo, "execute", outerr)
|
rep = runner.ItemTestReport(item, excinfo, "execute", outerr)
|
||||||
item.config.api.pytest_itemtestreport(rep=rep)
|
item.config.hook.pytest_itemtestreport(rep=rep)
|
||||||
|
|
||||||
def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
|
def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
|
||||||
pyfuncitem.obj(*args, **kwargs)
|
pyfuncitem.obj(*args, **kwargs)
|
||||||
|
@ -187,7 +187,7 @@ def test_implied_different_sessions(tmpdir):
|
||||||
assert x('-f') == 'LooponfailingSession'
|
assert x('-f') == 'LooponfailingSession'
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(DefaultPlugin)
|
plugintester.hookcheck(DefaultPlugin)
|
||||||
|
|
||||||
def test_plugin_specify(testdir):
|
def test_plugin_specify(testdir):
|
||||||
testdir.chdir()
|
testdir.chdir()
|
||||||
|
|
|
@ -162,5 +162,5 @@ class TestDoctests:
|
||||||
|
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(DoctestPlugin)
|
plugintester.hookcheck(DoctestPlugin)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class EventlogPlugin:
|
||||||
|
|
||||||
@py.test.mark.xfail
|
@py.test.mark.xfail
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(EventlogPlugin)
|
plugintester.hookcheck(EventlogPlugin)
|
||||||
|
|
||||||
testdir = plugintester.testdir()
|
testdir = plugintester.testdir()
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
|
|
|
@ -43,7 +43,7 @@ class ExecnetcleanupPlugin:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(ExecnetcleanupPlugin)
|
plugintester.hookcheck(ExecnetcleanupPlugin)
|
||||||
|
|
||||||
@py.test.mark.xfail("clarify plugin registration/unregistration")
|
@py.test.mark.xfail("clarify plugin registration/unregistration")
|
||||||
def test_execnetplugin(testdir):
|
def test_execnetplugin(testdir):
|
||||||
|
|
|
@ -55,7 +55,7 @@ class FigleafPlugin:
|
||||||
|
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(FigleafPlugin)
|
plugintester.hookcheck(FigleafPlugin)
|
||||||
|
|
||||||
def test_functional(testdir):
|
def test_functional(testdir):
|
||||||
py.test.importorskip("figleaf")
|
py.test.importorskip("figleaf")
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Capture:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(IocapturePlugin)
|
plugintester.hookcheck(IocapturePlugin)
|
||||||
|
|
||||||
class TestCapture:
|
class TestCapture:
|
||||||
def test_std_functional(self, testdir):
|
def test_std_functional(self, testdir):
|
||||||
|
|
|
@ -25,7 +25,7 @@ class PluginTester:
|
||||||
# break
|
# break
|
||||||
return crunner
|
return crunner
|
||||||
|
|
||||||
def apicheck(self, pluginclass):
|
def hookcheck(self, pluginclass):
|
||||||
print "loading and checking", pluginclass
|
print "loading and checking", pluginclass
|
||||||
fail = False
|
fail = False
|
||||||
pm = py.test._PluginManager()
|
pm = py.test._PluginManager()
|
||||||
|
@ -84,4 +84,4 @@ def formatdef(func):
|
||||||
# ===============================================================================
|
# ===============================================================================
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(PlugintesterPlugin)
|
plugintester.hookcheck(PlugintesterPlugin)
|
||||||
|
|
|
@ -41,7 +41,7 @@ class PocooPlugin:
|
||||||
|
|
||||||
|
|
||||||
def test_apicheck(plugintester):
|
def test_apicheck(plugintester):
|
||||||
plugintester.apicheck(PocooPlugin)
|
plugintester.hookcheck(PocooPlugin)
|
||||||
|
|
||||||
def test_toproxy(testdir, monkeypatch):
|
def test_toproxy(testdir, monkeypatch):
|
||||||
l = []
|
l = []
|
||||||
|
|
|
@ -51,7 +51,7 @@ class PylintItem(py.test.collect.Item):
|
||||||
print rating
|
print rating
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(PylintPlugin)
|
plugintester.hookcheck(PylintPlugin)
|
||||||
|
|
||||||
#def test_functional <pull from figleaf plugin>
|
#def test_functional <pull from figleaf plugin>
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class PytesterPlugin:
|
||||||
return evrec
|
return evrec
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(PytesterPlugin)
|
plugintester.hookcheck(PytesterPlugin)
|
||||||
|
|
||||||
class RunResult:
|
class RunResult:
|
||||||
def __init__(self, ret, outlines, errlines):
|
def __init__(self, ret, outlines, errlines):
|
||||||
|
@ -78,7 +78,7 @@ class TmpTestdir:
|
||||||
sorter = EventRecorder(registry)
|
sorter = EventRecorder(registry)
|
||||||
sorter.callrecorder = CallRecorder(registry)
|
sorter.callrecorder = CallRecorder(registry)
|
||||||
sorter.callrecorder.start_recording(api.PluginHooks)
|
sorter.callrecorder.start_recording(api.PluginHooks)
|
||||||
sorter.api = sorter.callrecorder.api
|
sorter.hook = sorter.callrecorder.hook
|
||||||
self.request.addfinalizer(sorter.callrecorder.finalize)
|
self.request.addfinalizer(sorter.callrecorder.finalize)
|
||||||
return sorter
|
return sorter
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ def test_eventrecorder(testdir):
|
||||||
rep = runner.ItemTestReport(None, None)
|
rep = runner.ItemTestReport(None, None)
|
||||||
rep.passed = False
|
rep.passed = False
|
||||||
rep.failed = True
|
rep.failed = True
|
||||||
recorder.api.pytest_itemtestreport(rep=rep)
|
recorder.hook.pytest_itemtestreport(rep=rep)
|
||||||
failures = recorder.getfailures()
|
failures = recorder.getfailures()
|
||||||
assert failures == [rep]
|
assert failures == [rep]
|
||||||
failures = recorder.getfailures()
|
failures = recorder.getfailures()
|
||||||
|
@ -394,12 +394,12 @@ def test_eventrecorder(testdir):
|
||||||
rep = runner.ItemTestReport(None, None)
|
rep = runner.ItemTestReport(None, None)
|
||||||
rep.passed = False
|
rep.passed = False
|
||||||
rep.skipped = True
|
rep.skipped = True
|
||||||
recorder.api.pytest_itemtestreport(rep=rep)
|
recorder.hook.pytest_itemtestreport(rep=rep)
|
||||||
|
|
||||||
rep = runner.CollectReport(None, None)
|
rep = runner.CollectReport(None, None)
|
||||||
rep.passed = False
|
rep.passed = False
|
||||||
rep.failed = True
|
rep.failed = True
|
||||||
recorder.api.pytest_itemtestreport(rep=rep)
|
recorder.hook.pytest_itemtestreport(rep=rep)
|
||||||
|
|
||||||
passed, skipped, failed = recorder.listoutcomes()
|
passed, skipped, failed = recorder.listoutcomes()
|
||||||
assert not passed and skipped and failed
|
assert not passed and skipped and failed
|
||||||
|
@ -412,7 +412,7 @@ def test_eventrecorder(testdir):
|
||||||
recorder.unregister()
|
recorder.unregister()
|
||||||
recorder.clear()
|
recorder.clear()
|
||||||
assert not recorder.getfailures()
|
assert not recorder.getfailures()
|
||||||
recorder.api.pytest_itemtestreport(rep=rep)
|
recorder.hook.pytest_itemtestreport(rep=rep)
|
||||||
assert not recorder.getfailures()
|
assert not recorder.getfailures()
|
||||||
|
|
||||||
class LineComp:
|
class LineComp:
|
||||||
|
|
|
@ -142,7 +142,7 @@ class ReSTSyntaxTest(py.test.collect.Item):
|
||||||
directives.register_directive('sourcecode', pygments_directive)
|
directives.register_directive('sourcecode', pygments_directive)
|
||||||
|
|
||||||
def resolve_linkrole(self, name, text, check=True):
|
def resolve_linkrole(self, name, text, check=True):
|
||||||
apigen_relpath = self.project.apigen_relpath
|
apigen_relpath = self.project.hookgen_relpath
|
||||||
|
|
||||||
if name == 'api':
|
if name == 'api':
|
||||||
if text == 'py':
|
if text == 'py':
|
||||||
|
@ -201,7 +201,7 @@ class DoctestText(py.test.collect.Item):
|
||||||
|
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
content = self._normalize_linesep()
|
content = self._normalize_linesep()
|
||||||
newcontent = self.config.api.pytest_doctest_prepare_content(content=content)
|
newcontent = self.config.hook.pytest_doctest_prepare_content(content=content)
|
||||||
if newcontent is not None:
|
if newcontent is not None:
|
||||||
content = newcontent
|
content = newcontent
|
||||||
s = content
|
s = content
|
||||||
|
@ -346,7 +346,7 @@ def localrefcheck(tryfn, path, lineno):
|
||||||
# PLUGIN tests
|
# PLUGIN tests
|
||||||
#
|
#
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(RestdocPlugin)
|
plugintester.hookcheck(RestdocPlugin)
|
||||||
|
|
||||||
def test_deindent():
|
def test_deindent():
|
||||||
assert deindent('foo') == 'foo'
|
assert deindent('foo') == 'foo'
|
||||||
|
|
|
@ -365,7 +365,7 @@ class TestWithFunctionIntegration:
|
||||||
assert 'ValueError' in entry
|
assert 'ValueError' in entry
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(ResultdbPlugin)
|
plugintester.hookcheck(ResultdbPlugin)
|
||||||
testdir = plugintester.testdir()
|
testdir = plugintester.testdir()
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
import py
|
import py
|
||||||
|
|
|
@ -224,7 +224,7 @@ class TestWithFunctionIntegration:
|
||||||
assert 'ValueError' in entry
|
assert 'ValueError' in entry
|
||||||
|
|
||||||
def test_generic(plugintester, LineMatcher):
|
def test_generic(plugintester, LineMatcher):
|
||||||
plugintester.apicheck(ResultlogPlugin)
|
plugintester.hookcheck(ResultlogPlugin)
|
||||||
testdir = plugintester.testdir()
|
testdir = plugintester.testdir()
|
||||||
testdir.plugins.append("resultlog")
|
testdir.plugins.append("resultlog")
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
|
|
|
@ -13,15 +13,15 @@ class RunnerPlugin:
|
||||||
call = item.config.guardedcall(lambda: setupstate.prepare(item))
|
call = item.config.guardedcall(lambda: setupstate.prepare(item))
|
||||||
if call.excinfo:
|
if call.excinfo:
|
||||||
rep = ItemSetupReport(item, call.excinfo, call.outerr)
|
rep = ItemSetupReport(item, call.excinfo, call.outerr)
|
||||||
item.config.api.pytest_itemsetupreport(rep=rep)
|
item.config.hook.pytest_itemsetupreport(rep=rep)
|
||||||
else:
|
else:
|
||||||
call = item.config.guardedcall(lambda: item.runtest())
|
call = item.config.guardedcall(lambda: item.runtest())
|
||||||
item.config.api.pytest_item_runtest_finished(
|
item.config.hook.pytest_item_runtest_finished(
|
||||||
item=item, excinfo=call.excinfo, outerr=call.outerr)
|
item=item, excinfo=call.excinfo, outerr=call.outerr)
|
||||||
call = item.config.guardedcall(lambda: self.teardown_exact(item))
|
call = item.config.guardedcall(lambda: self.teardown_exact(item))
|
||||||
if call.excinfo:
|
if call.excinfo:
|
||||||
rep = ItemSetupReport(item, call.excinfo, call.outerr)
|
rep = ItemSetupReport(item, call.excinfo, call.outerr)
|
||||||
item.config.api.pytest_itemsetupreport(rep=rep)
|
item.config.hook.pytest_itemsetupreport(rep=rep)
|
||||||
|
|
||||||
def pytest_collector_collect(self, collector):
|
def pytest_collector_collect(self, collector):
|
||||||
call = item.config.guardedcall(lambda x: collector._memocollect())
|
call = item.config.guardedcall(lambda x: collector._memocollect())
|
||||||
|
@ -146,7 +146,7 @@ class SetupState(object):
|
||||||
# ===============================================================================
|
# ===============================================================================
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(RunnerPlugin())
|
plugintester.hookcheck(RunnerPlugin())
|
||||||
|
|
||||||
class TestSetupState:
|
class TestSetupState:
|
||||||
def test_setup_prepare(self, testdir):
|
def test_setup_prepare(self, testdir):
|
||||||
|
|
|
@ -61,7 +61,7 @@ class TerminalReporter:
|
||||||
self._tw.sep(sep, title, **markup)
|
self._tw.sep(sep, title, **markup)
|
||||||
|
|
||||||
def getcategoryletterword(self, rep):
|
def getcategoryletterword(self, rep):
|
||||||
res = self.config.api.pytest_report_teststatus(rep=rep)
|
res = self.config.hook.pytest_report_teststatus(rep=rep)
|
||||||
if res:
|
if res:
|
||||||
return res
|
return res
|
||||||
for cat in 'skipped failed passed ???'.split():
|
for cat in 'skipped failed passed ???'.split():
|
||||||
|
@ -228,7 +228,7 @@ class TerminalReporter:
|
||||||
if exitstatus in (0, 1, 2):
|
if exitstatus in (0, 1, 2):
|
||||||
self.summary_failures()
|
self.summary_failures()
|
||||||
self.summary_skips()
|
self.summary_skips()
|
||||||
self.config.api.pytest_terminal_summary(terminalreporter=self)
|
self.config.hook.pytest_terminal_summary(terminalreporter=self)
|
||||||
if excrepr is not None:
|
if excrepr is not None:
|
||||||
self.summary_final_exc(excrepr)
|
self.summary_final_exc(excrepr)
|
||||||
if exitstatus == 2:
|
if exitstatus == 2:
|
||||||
|
@ -389,15 +389,15 @@ class TestTerminal:
|
||||||
""")
|
""")
|
||||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||||
rep.config.pluginmanager.register(rep)
|
rep.config.pluginmanager.register(rep)
|
||||||
rep.config.api.pytest_testrunstart()
|
rep.config.hook.pytest_testrunstart()
|
||||||
|
|
||||||
for item in testdir.genitems([modcol]):
|
for item in testdir.genitems([modcol]):
|
||||||
ev = runner.basic_run_report(item)
|
ev = runner.basic_run_report(item)
|
||||||
rep.config.api.pytest_itemtestreport(rep=ev)
|
rep.config.hook.pytest_itemtestreport(rep=ev)
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
"*test_pass_skip_fail.py .sF"
|
"*test_pass_skip_fail.py .sF"
|
||||||
])
|
])
|
||||||
rep.config.api.pytest_testrunfinish(exitstatus=1)
|
rep.config.hook.pytest_testrunfinish(exitstatus=1)
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
" def test_func():",
|
" def test_func():",
|
||||||
"> assert 0",
|
"> assert 0",
|
||||||
|
@ -416,21 +416,21 @@ class TestTerminal:
|
||||||
""", configargs=("-v",))
|
""", configargs=("-v",))
|
||||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||||
rep.config.pluginmanager.register(rep)
|
rep.config.pluginmanager.register(rep)
|
||||||
rep.config.api.pytest_testrunstart()
|
rep.config.hook.pytest_testrunstart()
|
||||||
items = modcol.collect()
|
items = modcol.collect()
|
||||||
rep.config.option.debug = True #
|
rep.config.option.debug = True #
|
||||||
for item in items:
|
for item in items:
|
||||||
rep.config.api.pytest_itemstart(item=item, node=None)
|
rep.config.hook.pytest_itemstart(item=item, node=None)
|
||||||
s = linecomp.stringio.getvalue().strip()
|
s = linecomp.stringio.getvalue().strip()
|
||||||
assert s.endswith(item.name)
|
assert s.endswith(item.name)
|
||||||
rep.config.api.pytest_itemtestreport(rep=runner.basic_run_report(item))
|
rep.config.hook.pytest_itemtestreport(rep=runner.basic_run_report(item))
|
||||||
|
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
"*test_pass_skip_fail_verbose.py:2: *test_ok*PASS*",
|
"*test_pass_skip_fail_verbose.py:2: *test_ok*PASS*",
|
||||||
"*test_pass_skip_fail_verbose.py:4: *test_skip*SKIP*",
|
"*test_pass_skip_fail_verbose.py:4: *test_skip*SKIP*",
|
||||||
"*test_pass_skip_fail_verbose.py:6: *test_func*FAIL*",
|
"*test_pass_skip_fail_verbose.py:6: *test_func*FAIL*",
|
||||||
])
|
])
|
||||||
rep.config.api.pytest_testrunfinish(exitstatus=1)
|
rep.config.hook.pytest_testrunfinish(exitstatus=1)
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
" def test_func():",
|
" def test_func():",
|
||||||
"> assert 0",
|
"> assert 0",
|
||||||
|
@ -441,13 +441,13 @@ class TestTerminal:
|
||||||
modcol = testdir.getmodulecol("import xyz")
|
modcol = testdir.getmodulecol("import xyz")
|
||||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||||
rep.config.pluginmanager.register(rep)
|
rep.config.pluginmanager.register(rep)
|
||||||
rep.config.api.pytest_testrunstart()
|
rep.config.hook.pytest_testrunstart()
|
||||||
l = list(testdir.genitems([modcol]))
|
l = list(testdir.genitems([modcol]))
|
||||||
assert len(l) == 0
|
assert len(l) == 0
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
"*test_collect_fail.py F*"
|
"*test_collect_fail.py F*"
|
||||||
])
|
])
|
||||||
rep.config.api.pytest_testrunfinish(exitstatus=1)
|
rep.config.hook.pytest_testrunfinish(exitstatus=1)
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
"> import xyz",
|
"> import xyz",
|
||||||
"E ImportError: No module named xyz"
|
"E ImportError: No module named xyz"
|
||||||
|
@ -537,11 +537,11 @@ class TestTerminal:
|
||||||
""", configargs=("--tb=%s" % tbopt,))
|
""", configargs=("--tb=%s" % tbopt,))
|
||||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||||
rep.config.pluginmanager.register(rep)
|
rep.config.pluginmanager.register(rep)
|
||||||
rep.config.api.pytest_testrunstart()
|
rep.config.hook.pytest_testrunstart()
|
||||||
for item in testdir.genitems([modcol]):
|
for item in testdir.genitems([modcol]):
|
||||||
rep.config.api.pytest_itemtestreport(
|
rep.config.hook.pytest_itemtestreport(
|
||||||
rep=runner.basic_run_report(item))
|
rep=runner.basic_run_report(item))
|
||||||
rep.config.api.pytest_testrunfinish(exitstatus=1)
|
rep.config.hook.pytest_testrunfinish(exitstatus=1)
|
||||||
s = linecomp.stringio.getvalue()
|
s = linecomp.stringio.getvalue()
|
||||||
if tbopt == "long":
|
if tbopt == "long":
|
||||||
print s
|
print s
|
||||||
|
@ -561,7 +561,7 @@ class TestTerminal:
|
||||||
item = testdir.getitem("def test_func(): pass")
|
item = testdir.getitem("def test_func(): pass")
|
||||||
rep = TerminalReporter(item.config, file=linecomp.stringio)
|
rep = TerminalReporter(item.config, file=linecomp.stringio)
|
||||||
item.config.pluginmanager.register(rep)
|
item.config.pluginmanager.register(rep)
|
||||||
rep.config.api.pytest_itemstart(item=item)
|
rep.config.hook.pytest_itemstart(item=item)
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
"*test_show_path_before_running_test.py*"
|
"*test_show_path_before_running_test.py*"
|
||||||
])
|
])
|
||||||
|
@ -578,10 +578,10 @@ class TestTerminal:
|
||||||
#""", configargs=("--showskipsummary",) + ("-v",)*verbose)
|
#""", configargs=("--showskipsummary",) + ("-v",)*verbose)
|
||||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||||
modcol.config.pluginmanager.register(rep)
|
modcol.config.pluginmanager.register(rep)
|
||||||
modcol.config.api.pytest_testrunstart()
|
modcol.config.hook.pytest_testrunstart()
|
||||||
try:
|
try:
|
||||||
for item in testdir.genitems([modcol]):
|
for item in testdir.genitems([modcol]):
|
||||||
modcol.config.api.pytest_itemtestreport(
|
modcol.config.hook.pytest_itemtestreport(
|
||||||
rep=runner.basic_run_report(item))
|
rep=runner.basic_run_report(item))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
|
@ -590,7 +590,7 @@ class TestTerminal:
|
||||||
s = linecomp.stringio.getvalue()
|
s = linecomp.stringio.getvalue()
|
||||||
if not verbose:
|
if not verbose:
|
||||||
assert s.find("_keyboard_interrupt.py Fs") != -1
|
assert s.find("_keyboard_interrupt.py Fs") != -1
|
||||||
modcol.config.api.pytest_testrunfinish(exitstatus=2, excrepr=excinfo.getrepr())
|
modcol.config.hook.pytest_testrunfinish(exitstatus=2, excrepr=excinfo.getrepr())
|
||||||
text = linecomp.stringio.getvalue()
|
text = linecomp.stringio.getvalue()
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
" def test_foobar():",
|
" def test_foobar():",
|
||||||
|
@ -640,16 +640,16 @@ class TestCollectonly:
|
||||||
rep = CollectonlyReporter(modcol.config, out=linecomp.stringio)
|
rep = CollectonlyReporter(modcol.config, out=linecomp.stringio)
|
||||||
modcol.config.pluginmanager.register(rep)
|
modcol.config.pluginmanager.register(rep)
|
||||||
indent = rep.indent
|
indent = rep.indent
|
||||||
rep.config.api.pytest_collectstart(collector=modcol)
|
rep.config.hook.pytest_collectstart(collector=modcol)
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
"<Module 'test_collectonly_basic.py'>"
|
"<Module 'test_collectonly_basic.py'>"
|
||||||
])
|
])
|
||||||
item = modcol.join("test_func")
|
item = modcol.join("test_func")
|
||||||
rep.config.api.pytest_itemstart(item=item)
|
rep.config.hook.pytest_itemstart(item=item)
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
" <Function 'test_func'>",
|
" <Function 'test_func'>",
|
||||||
])
|
])
|
||||||
rep.config.api.pytest_collectreport(
|
rep.config.hook.pytest_collectreport(
|
||||||
rep=runner.CollectReport(modcol, [], excinfo=None))
|
rep=runner.CollectReport(modcol, [], excinfo=None))
|
||||||
assert rep.indent == indent
|
assert rep.indent == indent
|
||||||
|
|
||||||
|
@ -687,6 +687,6 @@ def test_repr_python_version(monkeypatch):
|
||||||
assert repr_pythonversion() == str(x)
|
assert repr_pythonversion() == str(x)
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(TerminalPlugin)
|
plugintester.hookcheck(TerminalPlugin)
|
||||||
plugintester.apicheck(TerminalReporter)
|
plugintester.hookcheck(TerminalReporter)
|
||||||
plugintester.apicheck(CollectonlyReporter)
|
plugintester.hookcheck(CollectonlyReporter)
|
||||||
|
|
|
@ -24,7 +24,7 @@ class TmpdirPlugin:
|
||||||
# ===============================================================================
|
# ===============================================================================
|
||||||
#
|
#
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(TmpdirPlugin)
|
plugintester.hookcheck(TmpdirPlugin)
|
||||||
|
|
||||||
def test_funcarg(testdir):
|
def test_funcarg(testdir):
|
||||||
item = testdir.getitem("def test_func(tmpdir): pass")
|
item = testdir.getitem("def test_func(tmpdir): pass")
|
||||||
|
|
|
@ -71,7 +71,7 @@ class UnitTestFunction(py.test.collect.Function):
|
||||||
|
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(UnittestPlugin)
|
plugintester.hookcheck(UnittestPlugin)
|
||||||
|
|
||||||
def test_simple_unittest(testdir):
|
def test_simple_unittest(testdir):
|
||||||
testpath = testdir.makepyfile("""
|
testpath = testdir.makepyfile("""
|
||||||
|
|
|
@ -57,7 +57,7 @@ class XfailPlugin(object):
|
||||||
# ===============================================================================
|
# ===============================================================================
|
||||||
|
|
||||||
def test_generic(plugintester):
|
def test_generic(plugintester):
|
||||||
plugintester.apicheck(XfailPlugin)
|
plugintester.hookcheck(XfailPlugin)
|
||||||
|
|
||||||
def test_xfail(plugintester, linecomp):
|
def test_xfail(plugintester, linecomp):
|
||||||
testdir = plugintester.testdir()
|
testdir = plugintester.testdir()
|
||||||
|
|
|
@ -12,17 +12,17 @@ class PluginManager(object):
|
||||||
self.MultiCall = self.comregistry.MultiCall
|
self.MultiCall = self.comregistry.MultiCall
|
||||||
self.impname2plugin = {}
|
self.impname2plugin = {}
|
||||||
|
|
||||||
self.api = py._com.PluginAPI(
|
self.hook = py._com.Hooks(
|
||||||
apiclass=api.PluginHooks,
|
hookspecs=api.PluginHooks,
|
||||||
registry=self.comregistry)
|
registry=self.comregistry)
|
||||||
|
|
||||||
def register(self, plugin):
|
def register(self, plugin):
|
||||||
self.api.pytest_plugin_registered(plugin=plugin)
|
self.hook.pytest_plugin_registered(plugin=plugin)
|
||||||
import types
|
import types
|
||||||
self.comregistry.register(plugin)
|
self.comregistry.register(plugin)
|
||||||
|
|
||||||
def unregister(self, plugin):
|
def unregister(self, plugin):
|
||||||
self.api.pytest_plugin_unregistered(plugin=plugin)
|
self.hook.pytest_plugin_unregistered(plugin=plugin)
|
||||||
self.comregistry.unregister(plugin)
|
self.comregistry.unregister(plugin)
|
||||||
|
|
||||||
def isregistered(self, plugin):
|
def isregistered(self, plugin):
|
||||||
|
@ -95,7 +95,7 @@ class PluginManager(object):
|
||||||
if excinfo is None:
|
if excinfo is None:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
excrepr = excinfo.getrepr(funcargs=True, showlocals=True)
|
excrepr = excinfo.getrepr(funcargs=True, showlocals=True)
|
||||||
return self.api.pytest_internalerror(excrepr=excrepr)
|
return self.hook.pytest_internalerror(excrepr=excrepr)
|
||||||
|
|
||||||
def do_addoption(self, parser):
|
def do_addoption(self, parser):
|
||||||
methods = self.comregistry.listattr("pytest_addoption", reverse=True)
|
methods = self.comregistry.listattr("pytest_addoption", reverse=True)
|
||||||
|
@ -115,12 +115,12 @@ class PluginManager(object):
|
||||||
assert not hasattr(self, '_config')
|
assert not hasattr(self, '_config')
|
||||||
config.pluginmanager.register(self)
|
config.pluginmanager.register(self)
|
||||||
self._config = config
|
self._config = config
|
||||||
config.api.pytest_configure(config=self._config)
|
config.hook.pytest_configure(config=self._config)
|
||||||
|
|
||||||
def do_unconfigure(self, config):
|
def do_unconfigure(self, config):
|
||||||
config = self._config
|
config = self._config
|
||||||
del self._config
|
del self._config
|
||||||
config.api.pytest_unconfigure(config=config)
|
config.hook.pytest_unconfigure(config=config)
|
||||||
config.pluginmanager.unregister(self)
|
config.pluginmanager.unregister(self)
|
||||||
|
|
||||||
def do_itemrun(self, item, pdb=None):
|
def do_itemrun(self, item, pdb=None):
|
||||||
|
|
|
@ -135,7 +135,7 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
|
||||||
return self.join(name)
|
return self.join(name)
|
||||||
|
|
||||||
def makeitem(self, name, obj):
|
def makeitem(self, name, obj):
|
||||||
res = self.config.api.pytest_pymodule_makeitem(
|
res = self.config.hook.pytest_pymodule_makeitem(
|
||||||
modcol=self, name=name, obj=obj)
|
modcol=self, name=name, obj=obj)
|
||||||
if res:
|
if res:
|
||||||
return res
|
return res
|
||||||
|
@ -345,7 +345,7 @@ class Function(FunctionMixin, py.test.collect.Item):
|
||||||
|
|
||||||
def runtest(self):
|
def runtest(self):
|
||||||
""" execute the given test function. """
|
""" execute the given test function. """
|
||||||
self.config.api.pytest_pyfunc_call(pyfuncitem=self,
|
self.config.hook.pytest_pyfunc_call(pyfuncitem=self,
|
||||||
args=self._args, kwargs=self.funcargs)
|
args=self._args, kwargs=self.funcargs)
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
|
|
@ -32,7 +32,7 @@ def basic_run_report(item, pdb=None):
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
testrep = item.config.api.pytest_item_makereport(
|
testrep = item.config.hook.pytest_item_makereport(
|
||||||
item=item, excinfo=excinfo, when=when, outerr=outerr)
|
item=item, excinfo=excinfo, when=when, outerr=outerr)
|
||||||
if pdb and testrep.failed:
|
if pdb and testrep.failed:
|
||||||
tw = py.io.TerminalWriter()
|
tw = py.io.TerminalWriter()
|
||||||
|
|
|
@ -37,16 +37,16 @@ class Session(object):
|
||||||
if isinstance(next, Item):
|
if isinstance(next, Item):
|
||||||
remaining = self.filteritems([next])
|
remaining = self.filteritems([next])
|
||||||
if remaining:
|
if remaining:
|
||||||
self.config.api.pytest_itemstart(item=next)
|
self.config.hook.pytest_itemstart(item=next)
|
||||||
yield next
|
yield next
|
||||||
else:
|
else:
|
||||||
assert isinstance(next, Collector)
|
assert isinstance(next, Collector)
|
||||||
self.config.api.pytest_collectstart(collector=next)
|
self.config.hook.pytest_collectstart(collector=next)
|
||||||
rep = basic_collect_report(next)
|
rep = basic_collect_report(next)
|
||||||
if rep.passed:
|
if rep.passed:
|
||||||
for x in self.genitems(rep.result, keywordexpr):
|
for x in self.genitems(rep.result, keywordexpr):
|
||||||
yield x
|
yield x
|
||||||
self.config.api.pytest_collectreport(rep=rep)
|
self.config.hook.pytest_collectreport(rep=rep)
|
||||||
if self.shouldstop:
|
if self.shouldstop:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class Session(object):
|
||||||
continue
|
continue
|
||||||
remaining.append(colitem)
|
remaining.append(colitem)
|
||||||
if deselected:
|
if deselected:
|
||||||
self.config.api.pytest_deselected(items=deselected)
|
self.config.hook.pytest_deselected(items=deselected)
|
||||||
if self.config.option.keyword.endswith(":"):
|
if self.config.option.keyword.endswith(":"):
|
||||||
self._nomatch = True
|
self._nomatch = True
|
||||||
return remaining
|
return remaining
|
||||||
|
@ -78,7 +78,7 @@ class Session(object):
|
||||||
|
|
||||||
def sessionstarts(self):
|
def sessionstarts(self):
|
||||||
""" setup any neccessary resources ahead of the test run. """
|
""" setup any neccessary resources ahead of the test run. """
|
||||||
self.config.api.pytest_testrunstart()
|
self.config.hook.pytest_testrunstart()
|
||||||
|
|
||||||
def pytest_itemtestreport(self, rep):
|
def pytest_itemtestreport(self, rep):
|
||||||
if rep.failed:
|
if rep.failed:
|
||||||
|
@ -89,7 +89,7 @@ class Session(object):
|
||||||
|
|
||||||
def sessionfinishes(self, exitstatus=0, excinfo=None):
|
def sessionfinishes(self, exitstatus=0, excinfo=None):
|
||||||
""" teardown any resources after a test run. """
|
""" teardown any resources after a test run. """
|
||||||
self.config.api.pytest_testrunfinish(
|
self.config.hook.pytest_testrunfinish(
|
||||||
exitstatus=exitstatus,
|
exitstatus=exitstatus,
|
||||||
excrepr=excinfo and excinfo.getrepr() or None
|
excrepr=excinfo and excinfo.getrepr() or None
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,4 +11,4 @@ class TestPyfuncHooks:
|
||||||
return True
|
return True
|
||||||
config.pluginmanager.register(MyPlugin1())
|
config.pluginmanager.register(MyPlugin1())
|
||||||
config.pluginmanager.register(MyPlugin2())
|
config.pluginmanager.register(MyPlugin2())
|
||||||
config.api.pytest_pyfunc_call(pyfuncitem=item)
|
config.hook.pytest_pyfunc_call(pyfuncitem=item)
|
||||||
|
|
|
@ -84,7 +84,7 @@ class TestBootstrapping:
|
||||||
#syspath.prepend(aplugin.dirpath())
|
#syspath.prepend(aplugin.dirpath())
|
||||||
py.std.sys.path.insert(0, str(aplugin.dirpath()))
|
py.std.sys.path.insert(0, str(aplugin.dirpath()))
|
||||||
pluginmanager.consider_module(mod)
|
pluginmanager.consider_module(mod)
|
||||||
call = sorter.getcall(pluginmanager.api.pytest_plugin_registered.name)
|
call = sorter.getcall(pluginmanager.hook.pytest_plugin_registered.name)
|
||||||
assert call.plugin.__class__.__name__ == "APlugin"
|
assert call.plugin.__class__.__name__ == "APlugin"
|
||||||
|
|
||||||
# check that it is not registered twice
|
# check that it is not registered twice
|
||||||
|
|
Loading…
Reference in New Issue