parent
2dd3ea7041
commit
0c4fc99a6f
|
@ -42,7 +42,7 @@ class Config(object):
|
||||||
self.pytestplugins = pytestplugins
|
self.pytestplugins = pytestplugins
|
||||||
self._conftest = Conftest(onimport=self._onimportconftest)
|
self._conftest = Conftest(onimport=self._onimportconftest)
|
||||||
self._setupstate = SetupState()
|
self._setupstate = SetupState()
|
||||||
self.api = pytestplugins._getapi()
|
self.api = pytestplugins.api
|
||||||
|
|
||||||
def _onimportconftest(self, conftestmodule):
|
def _onimportconftest(self, conftestmodule):
|
||||||
self.trace("loaded conftestmodule %r" %(conftestmodule,))
|
self.trace("loaded conftestmodule %r" %(conftestmodule,))
|
||||||
|
|
|
@ -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.bus.notify("trace", "nodemanage", msg)
|
self.config.api.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")
|
||||||
|
|
|
@ -198,15 +198,6 @@ class TestDSession:
|
||||||
session.loop_once(loopstate)
|
session.loop_once(loopstate)
|
||||||
assert len(session.node2pending) == 1
|
assert len(session.node2pending) == 1
|
||||||
|
|
||||||
def test_event_propagation(self, testdir):
|
|
||||||
item = testdir.getitem("def test_func(): pass")
|
|
||||||
session = DSession(item.config)
|
|
||||||
|
|
||||||
evrec = testdir.geteventrecorder(session.bus)
|
|
||||||
session.queueevent("NOP", 42)
|
|
||||||
session.loop_once(session._initloopstate([]))
|
|
||||||
assert evrec.getcall('NOP')
|
|
||||||
|
|
||||||
def runthrough(self, item):
|
def runthrough(self, item):
|
||||||
session = DSession(item.config)
|
session = DSession(item.config)
|
||||||
node = MockNode()
|
node = MockNode()
|
||||||
|
|
|
@ -104,11 +104,10 @@ class TestNodeManager:
|
||||||
config = py.test.config._reparse([source, '--debug'])
|
config = py.test.config._reparse([source, '--debug'])
|
||||||
assert config.option.debug
|
assert config.option.debug
|
||||||
nodemanager = NodeManager(config, specs)
|
nodemanager = NodeManager(config, specs)
|
||||||
sorter = testdir.geteventrecorder(config.bus)
|
sorter = testdir.geteventrecorder(config.bus).callrecorder
|
||||||
nodemanager.setup_nodes(putevent=[].append)
|
nodemanager.setup_nodes(putevent=[].append)
|
||||||
for spec in nodemanager.gwmanager.specs:
|
for spec in nodemanager.gwmanager.specs:
|
||||||
l = sorter.getcalls("trace")
|
l = sorter.getcalls("pytest_trace")
|
||||||
print sorter.events
|
|
||||||
assert l
|
assert l
|
||||||
nodemanager.teardown_nodes()
|
nodemanager.teardown_nodes()
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,6 @@ class EventQueue:
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
bus.register(self)
|
bus.register(self)
|
||||||
|
|
||||||
def pyevent(self, eventname, args, kwargs):
|
|
||||||
self.queue.put((eventname, args, kwargs))
|
|
||||||
|
|
||||||
def geteventargs(self, eventname, timeout=2.0):
|
def geteventargs(self, eventname, timeout=2.0):
|
||||||
events = []
|
events = []
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -30,7 +27,7 @@ class EventQueue:
|
||||||
return args
|
return args
|
||||||
return kwargs
|
return kwargs
|
||||||
events.append(name)
|
events.append(name)
|
||||||
if name == "internalerror":
|
if name == "pytest_internalerror":
|
||||||
print str(kwargs["excrepr"])
|
print str(kwargs["excrepr"])
|
||||||
|
|
||||||
class MySetup:
|
class MySetup:
|
||||||
|
@ -113,7 +110,7 @@ class TestMasterSlaveConnection:
|
||||||
node = mysetup.makenode(item.config)
|
node = mysetup.makenode(item.config)
|
||||||
node.channel.close()
|
node.channel.close()
|
||||||
py.test.raises(IOError, "node.send(item)")
|
py.test.raises(IOError, "node.send(item)")
|
||||||
#ev = self.getcalls("internalerror")
|
#ev = self.getcalls(pytest_internalerror)
|
||||||
#assert ev.excinfo.errisinstance(IOError)
|
#assert ev.excinfo.errisinstance(IOError)
|
||||||
|
|
||||||
def test_send_one(self, testdir, mysetup):
|
def test_send_one(self, testdir, mysetup):
|
||||||
|
|
|
@ -130,5 +130,5 @@ class SlaveNode(object):
|
||||||
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("pytest_internalerror", excrepr=er)
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -113,19 +113,9 @@ class PluginHooks:
|
||||||
def pytest_looponfailinfo(self, failreports, rootdirs):
|
def pytest_looponfailinfo(self, failreports, rootdirs):
|
||||||
""" info for repeating failing tests. """
|
""" info for repeating failing tests. """
|
||||||
|
|
||||||
|
def pytest_internalerror(self, excrepr):
|
||||||
class Events:
|
|
||||||
# Events
|
|
||||||
def pyevent(self, eventname, args, kwargs):
|
|
||||||
""" generically called for each notification event. """
|
|
||||||
|
|
||||||
def pyevent__NOP(self, *args, **kwargs):
|
|
||||||
""" the no-operation call. """
|
|
||||||
|
|
||||||
def pyevent__trace(self, category, msg):
|
|
||||||
""" called for tracing events. """
|
|
||||||
|
|
||||||
def pyevent__internalerror(self, excrepr):
|
|
||||||
""" called for internal errors. """
|
""" called for internal errors. """
|
||||||
|
|
||||||
|
def pytest_trace(self, category, msg):
|
||||||
|
""" called for tracing events. """
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ class PluginTester(Support):
|
||||||
pm = py.test._PytestPlugins()
|
pm = py.test._PytestPlugins()
|
||||||
methods = collectattr(pluginclass)
|
methods = collectattr(pluginclass)
|
||||||
hooks = collectattr(api.PluginHooks)
|
hooks = collectattr(api.PluginHooks)
|
||||||
hooks.update(collectattr(api.Events))
|
|
||||||
getargs = py.std.inspect.getargs
|
getargs = py.std.inspect.getargs
|
||||||
|
|
||||||
def isgenerichook(name):
|
def isgenerichook(name):
|
||||||
|
@ -78,7 +77,7 @@ class PluginTester(Support):
|
||||||
if fail:
|
if fail:
|
||||||
py.test.fail("Plugin API error")
|
py.test.fail("Plugin API error")
|
||||||
|
|
||||||
def collectattr(obj, prefixes=("pytest_", "pyevent__")):
|
def collectattr(obj, prefixes=("pytest_",)):
|
||||||
methods = {}
|
methods = {}
|
||||||
for apiname in vars(obj):
|
for apiname in vars(obj):
|
||||||
for prefix in prefixes:
|
for prefix in prefixes:
|
||||||
|
|
|
@ -285,13 +285,6 @@ class EventRecorder(object):
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
pyplugins.register(self)
|
pyplugins.register(self)
|
||||||
|
|
||||||
def pyevent(self, name, args, kwargs):
|
|
||||||
if name == "plugin_registered" and args == (self,):
|
|
||||||
return
|
|
||||||
if self.debug:
|
|
||||||
print "[event: %s]: %s **%s" %(name, ", ".join(map(str, args)), kwargs,)
|
|
||||||
self.events.append(Event(name, args, kwargs))
|
|
||||||
|
|
||||||
def popcall(self, name):
|
def popcall(self, name):
|
||||||
for i, event in py.builtin.enumerate(self.events):
|
for i, event in py.builtin.enumerate(self.events):
|
||||||
if event.name == name:
|
if event.name == name:
|
||||||
|
|
|
@ -349,7 +349,7 @@ class TestWithFunctionIntegration:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
reslog = ResultDB(StringIO.StringIO())
|
reslog = ResultDB(StringIO.StringIO())
|
||||||
reslog.pyevent__internalerror(excinfo.getrepr)
|
reslog.pytest_internalerror(excinfo.getrepr)
|
||||||
entry = reslog.logfile.getvalue()
|
entry = reslog.logfile.getvalue()
|
||||||
entry_lines = entry.splitlines()
|
entry_lines = entry.splitlines()
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ class ResultLog(object):
|
||||||
longrepr = str(rep.longrepr.reprcrash)
|
longrepr = str(rep.longrepr.reprcrash)
|
||||||
self.log_outcome(rep, code, longrepr)
|
self.log_outcome(rep, code, longrepr)
|
||||||
|
|
||||||
def pyevent__internalerror(self, excrepr):
|
def pytest_internalerror(self, excrepr):
|
||||||
path = excrepr.reprcrash.path
|
path = excrepr.reprcrash.path
|
||||||
self.write_log_entry(path, '!', str(excrepr))
|
self.write_log_entry(path, '!', str(excrepr))
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ class TestWithFunctionIntegration:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
excinfo = py.code.ExceptionInfo()
|
excinfo = py.code.ExceptionInfo()
|
||||||
reslog = ResultLog(StringIO.StringIO())
|
reslog = ResultLog(StringIO.StringIO())
|
||||||
reslog.pyevent__internalerror(excinfo.getrepr())
|
reslog.pytest_internalerror(excinfo.getrepr())
|
||||||
entry = reslog.logfile.getvalue()
|
entry = reslog.logfile.getvalue()
|
||||||
entry_lines = entry.splitlines()
|
entry_lines = entry.splitlines()
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ class TerminalReporter:
|
||||||
else:
|
else:
|
||||||
return "???", dict(red=True)
|
return "???", dict(red=True)
|
||||||
|
|
||||||
def pyevent__internalerror(self, excrepr):
|
def pytest_internalerror(self, excrepr):
|
||||||
for line in str(excrepr).split("\n"):
|
for line in str(excrepr).split("\n"):
|
||||||
self.write_line("INTERNALERROR> " + line)
|
self.write_line("INTERNALERROR> " + line)
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ class TerminalReporter:
|
||||||
if error:
|
if error:
|
||||||
self.write_line("%s node down, error: %s" %(node.gateway.id, error))
|
self.write_line("%s node down, error: %s" %(node.gateway.id, error))
|
||||||
|
|
||||||
def pyevent__trace(self, category, msg):
|
def pytest_trace(self, category, msg):
|
||||||
if self.config.option.debug or \
|
if self.config.option.debug or \
|
||||||
self.config.option.traceconfig and category.find("config") != -1:
|
self.config.option.traceconfig and category.find("config") != -1:
|
||||||
self.write_line("[%s] %s" %(category, msg))
|
self.write_line("[%s] %s" %(category, msg))
|
||||||
|
@ -437,7 +437,7 @@ class TestTerminal:
|
||||||
modcol = testdir.getmodulecol("def test_one(): pass")
|
modcol = testdir.getmodulecol("def test_one(): pass")
|
||||||
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
|
||||||
excinfo = py.test.raises(ValueError, "raise ValueError('hello')")
|
excinfo = py.test.raises(ValueError, "raise ValueError('hello')")
|
||||||
rep.pyevent__internalerror(excinfo.getrepr())
|
rep.pytest_internalerror(excinfo.getrepr())
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
"INTERNALERROR> *raise ValueError*"
|
"INTERNALERROR> *raise ValueError*"
|
||||||
])
|
])
|
||||||
|
|
|
@ -12,9 +12,9 @@ class PytestPlugins(object):
|
||||||
self.MultiCall = self.pyplugins.MultiCall
|
self.MultiCall = self.pyplugins.MultiCall
|
||||||
self._plugins = {}
|
self._plugins = {}
|
||||||
|
|
||||||
def _getapi(self):
|
self.api = py._com.PluginAPI(
|
||||||
return py._com.PluginAPI(apiclass=api.PluginHooks,
|
apiclass=api.PluginHooks,
|
||||||
plugins=self.pyplugins)
|
plugins=self.pyplugins)
|
||||||
|
|
||||||
def register(self, plugin):
|
def register(self, plugin):
|
||||||
self.pyplugins.register(plugin)
|
self.pyplugins.register(plugin)
|
||||||
|
@ -86,7 +86,7 @@ class PytestPlugins(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.notify("internalerror", excrepr=excrepr)
|
return self.api.pytest_internalerror(excrepr=excrepr)
|
||||||
|
|
||||||
def do_addoption(self, parser):
|
def do_addoption(self, parser):
|
||||||
methods = self.pyplugins.listattr("pytest_addoption", reverse=True)
|
methods = self.pyplugins.listattr("pytest_addoption", reverse=True)
|
||||||
|
|
|
@ -176,7 +176,7 @@ class TestPytestPluginInteractions:
|
||||||
class A:
|
class A:
|
||||||
def pytest_configure(self, config):
|
def pytest_configure(self, config):
|
||||||
l.append(self)
|
l.append(self)
|
||||||
def pyevent__hello(self, obj):
|
def xyz(self, obj):
|
||||||
events.append(obj)
|
events.append(obj)
|
||||||
|
|
||||||
config.bus.register(A())
|
config.bus.register(A())
|
||||||
|
@ -187,7 +187,7 @@ class TestPytestPluginInteractions:
|
||||||
assert len(l) == 2
|
assert len(l) == 2
|
||||||
assert l[0] != l[1]
|
assert l[0] != l[1]
|
||||||
|
|
||||||
config.bus.notify("hello", 42)
|
config.bus.call_each("xyz", obj=42)
|
||||||
assert len(events) == 2
|
assert len(events) == 2
|
||||||
assert events == [42,42]
|
assert events == [42,42]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue