test and fix tracing indentation in case of exceptions

This commit is contained in:
holger krekel 2010-11-06 20:06:32 +01:00
parent 1899443744
commit b3628daa62
2 changed files with 19 additions and 9 deletions

View File

@ -389,9 +389,11 @@ class HookCaller:
self.trace(self.name, kwargs)
self.trace.root.indent += 1
mc = MultiCall(methods, kwargs, firstresult=self.firstresult)
try:
res = mc.execute()
if res:
self.trace(res)
finally:
self.trace.root.indent -= 1
return res

View File

@ -266,18 +266,26 @@ class TestBootstrapping:
l = list(plugins.listattr('x'))
assert l == [41, 42, 43]
def test_register_trace(self):
def test_hook_tracing(self):
pm = PluginManager()
saveindent = []
class api1:
x = 41
def pytest_plugin_registered(self, plugin):
saveindent.append(pm.trace.root.indent)
raise ValueError(42)
l = []
pm.trace.setmyprocessor(lambda kw, args: l.append((kw, args)))
pm.trace.root.setwriter(l.append)
indent = pm.trace.root.indent
p = api1()
pm.register(p)
assert pm.trace.root.indent == indent
assert len(l) == 1
kw, args = l[0]
assert args[0] == "registered"
assert args[1] == p
assert 'pytest_plugin_registered' in l[0]
py.test.raises(ValueError, lambda: pm.register(api1()))
assert pm.trace.root.indent == indent
assert saveindent[0] > indent
class TestPytestPluginInteractions: