[svn r63593] have plugin method run the test item and report about it

--HG--
branch : trunk
This commit is contained in:
hpk 2009-04-04 00:36:29 +02:00
parent db60fe7f37
commit f14b0c90d9
6 changed files with 19 additions and 15 deletions

View File

@ -7,9 +7,10 @@ import py
XSpec = py.execnet.XSpec XSpec = py.execnet.XSpec
def run(item, node): def run(item, node):
report = item.config.pytestplugins.do_itemrun(item) from py.__.test.runner import basic_run_report
report.node = node rep = basic_run_report(item)
return report rep.node = node
return rep
class MockNode: class MockNode:
def __init__(self): def __init__(self):
@ -218,7 +219,7 @@ class TestDSession:
session.loop_once(loopstate) session.loop_once(loopstate)
assert node.sent == [[item]] assert node.sent == [[item]]
ev = run(item, node) ev = run(item, node)
session.queueevent("itemtestreport", ev) session.queueevent("itemtestreport", ev)
session.loop_once(loopstate) session.loop_once(loopstate)
assert loopstate.shuttingdown assert loopstate.shuttingdown

View File

@ -28,6 +28,8 @@ class EventQueue:
if name == eventname: if name == eventname:
return args return args
events.append(name) events.append(name)
if name == "internalerror":
print str(kwargs["excrepr"])
class MySetup: class MySetup:
def __init__(self, pyfuncitem): def __init__(self, pyfuncitem):

View File

@ -106,12 +106,16 @@ class SlaveNode(object):
def sendevent(self, eventname, *args, **kwargs): def sendevent(self, eventname, *args, **kwargs):
self.channel.send((eventname, args, kwargs)) self.channel.send((eventname, args, kwargs))
def pyevent__itemtestreport(self, report):
self.sendevent("itemtestreport", report)
def run(self): def run(self):
channel = self.channel channel = self.channel
self.config, basetemp = channel.receive() self.config, basetemp = channel.receive()
if basetemp: if basetemp:
self.config.basetemp = py.path.local(basetemp) self.config.basetemp = py.path.local(basetemp)
self.config.pytestplugins.do_configure(self.config) self.config.pytestplugins.do_configure(self.config)
self.config.pytestplugins.register(self)
self.sendevent("slaveready") self.sendevent("slaveready")
try: try:
while 1: while 1:
@ -121,16 +125,12 @@ class SlaveNode(object):
break break
if isinstance(task, list): if isinstance(task, list):
for item in task: for item in task:
self.runtest(item) item.config.pytestplugins.do_itemrun(item)
else: else:
self.runtest(task) task.config.pytestplugins.do_itemrun(item=task)
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
except: except:
er = py.code.ExceptionInfo().getrepr(funcargs=True, showlocals=True) er = py.code.ExceptionInfo().getrepr(funcargs=True, showlocals=True)
self.sendevent("internalerror", excrepr=er) self.sendevent("internalerror", excrepr=er)
raise raise
def runtest(self, item):
report = item.config.pytestplugins.do_itemrun(item)
self.sendevent("itemtestreport", report)

View File

@ -10,7 +10,8 @@ class DefaultPlugin:
else: else:
runner = basic_run_report runner = basic_run_report
report = runner(item, pdb=pdb) report = runner(item, pdb=pdb)
return report item.config.pytestplugins.notify("itemtestreport", report)
return True
def pytest_pyfunc_call(self, pyfuncitem, args, kwargs): def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
pyfuncitem.obj(*args, **kwargs) pyfuncitem.obj(*args, **kwargs)

View File

@ -106,7 +106,9 @@ class PytestPlugins(object):
config.bus.unregister(self) config.bus.unregister(self)
def do_itemrun(self, item, pdb=None): def do_itemrun(self, item, pdb=None):
return self.pyplugins.call_firstresult("pytest_itemrun", item=item, pdb=pdb) res = self.pyplugins.call_firstresult("pytest_itemrun", item=item, pdb=pdb)
if res is None:
raise ValueError("could not run %r" %(item,))
# #
# XXX old code to automatically load classes # XXX old code to automatically load classes

View File

@ -105,7 +105,6 @@ class Session(object):
colitems = self.getinitialitems(colitems) colitems = self.getinitialitems(colitems)
self.shouldstop = False self.shouldstop = False
self.sessionstarts() self.sessionstarts()
#self.bus.notify("testnodeready", maketestnodeready())
exitstatus = outcome.EXIT_OK exitstatus = outcome.EXIT_OK
captured_excinfo = None captured_excinfo = None
try: try:
@ -134,5 +133,4 @@ class Session(object):
def runtest(self, item): def runtest(self, item):
pdb = self.config.option.usepdb and self.runpdb or None pdb = self.config.option.usepdb and self.runpdb or None
report = item.config.pytestplugins.do_itemrun(item, pdb=pdb) item.config.pytestplugins.do_itemrun(item, pdb=pdb)
self.bus.notify("itemtestreport", report)