[PATCH 1/3] ExceptionCatcher hands over the Exception object

Kamil Páral kparal at redhat.com
Tue Sep 14 11:04:35 UTC 2010


From: Josef Skladanka <jskladan at redhat.com>

ExceptionCatcher calls the 'on_exception' method with a parameter
exc = exc_info[1] - i.e. the Exception object of the raised
Exception, so the methods called can read the exception info.
---
 lib/python/decorators.py |    4 ++--
 lib/python/test.py       |   22 ++++++++++++----------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/lib/python/decorators.py b/lib/python/decorators.py
index 727d0d5..0b920b4 100644
--- a/lib/python/decorators.py
+++ b/lib/python/decorators.py
@@ -76,10 +76,10 @@ class ExceptionCatcher(object):
                     #if the 'on_exception' is a name of 'class member function'
                     #then call the f_self.on_exception(oe_args, oe_kwargs)
                     if self.oe_is_self_method:
-                        f_self.__getattribute__(self.oe)(*self.oe_a, **self.oe_k)
+                        f_self.__getattribute__(self.oe)(exc = exc_info[1], *self.oe_a, **self.oe_k)
                     #'on_exception' is pointer to function
                     else:
-                        self.oe(*self.oe_a, **self.oe_k)
+                        self.oe(exc = exc_info[1], *self.oe_a, **self.oe_k)
                     #re-raise the stored exception
                     raise exc_info[1], None, exc_info[2]
                 return f_result
diff --git a/lib/python/test.py b/lib/python/test.py
index 15d6d16..20b35cd 100644
--- a/lib/python/test.py
+++ b/lib/python/test.py
@@ -43,21 +43,23 @@ class AutoQATest(test.test, object):
     def run_once(self, **kwargs):
         pass
 
-    def initialize_failed(self):
-        if self.result is None:
-            self.result = "CRASHED"
-        if self.summary == "":
-            self.summary = "%s: Initialize failed" % self.__class__.__name__
+    def initialize_failed(self, exc = None):
+        self.result = "CRASHED"
+        if exc is not None:
+            self.summary = "Initialize failed: %s: %s" % (exc.__class__.__name__, exc)
+        else:
+            self.summary = "Initialize failed: Exception: Unknown exception"
         try:
             self.postprocess_iteration()
         except:
             pass
 
-    def run_once_failed(self):
-        if self.result is None:
-            self.result = "CRASHED"
-        if self.summary == "":
-            self.summary = "%s: Run_once failed" % self.__class__.__name__
+    def run_once_failed(self, exc = None):
+        self.result = "CRASHED"
+        if exc is not None:
+            self.summary = "Run_once failed: %s: %s" % (exc.__class__.__name__, exc)
+        else:
+            self.summary = "Run_once failed: Exception: Unknown exception"
         try:
             self.postprocess_iteration()
         except:
-- 
1.7.2.2



More information about the autoqa-devel mailing list