# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User holger krekel <hol...@merlinux.eu>
# Date 1289070392 -3600
# Node ID 3986b64bdce8659f16e115c086b9c6dc075fe58c
# Parent  e7083ff9d8efeb354f4b5bdfff77158802a1aa06
test and fix tracing indentation in case of exceptions

--- 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:
 

--- 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
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to