diff --git a/pytest/main.py b/pytest/main.py index d7f356186..419de31d2 100644 --- a/pytest/main.py +++ b/pytest/main.py @@ -389,10 +389,12 @@ class HookCaller: self.trace(self.name, kwargs) self.trace.root.indent += 1 mc = MultiCall(methods, kwargs, firstresult=self.firstresult) - res = mc.execute() - if res: - self.trace(res) - self.trace.root.indent -= 1 + try: + res = mc.execute() + if res: + self.trace(res) + finally: + self.trace.root.indent -= 1 return res _preinit = [PluginManager(load=True)] # triggers default plugin importing diff --git a/testing/test_main.py b/testing/test_main.py index b2532104c..7903b3549 100644 --- a/testing/test_main.py +++ b/testing/test_main.py @@ -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: