diff mbox

[KVM-AUTOTEST,5/7,RFC] Set the .context attribute for exceptions in _call_test_function()

Message ID 1294079651-21631-5-git-send-email-mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish Jan. 3, 2011, 6:34 p.m. UTC
None
diff mbox

Patch

diff --git a/client/common_lib/test.py b/client/common_lib/test.py
index 2561242..9521326 100644
--- a/client/common_lib/test.py
+++ b/client/common_lib/test.py
@@ -596,13 +596,17 @@  def _call_test_function(func, *args, **dargs):
     inside test code are considered test failures."""
     try:
         return func(*args, **dargs)
-    except error.AutotestError:
-        # Pass already-categorized errors on up as is.
-        raise
+    except error.AutotestError, e:
+        # Inject context info and pass already-categorized errors on up.
+        e.context = error.get_context(sys.exc_info()[2])
+        raise sys.exc_info()[0], e, sys.exc_info()[2]
     except Exception, e:
-        # Other exceptions must be treated as a FAIL when
-        # raised during the test functions
-        raise error.UnhandledTestFail(e)
+        # Other exceptions are treated as a FAIL when raised during the test
+        # functions.  Convert them to UnhandledTestFail, inject context info
+        # and pass them on up.
+        e = error.UnhandledTestFail(e)
+        e.context = error.get_context(sys.exc_info()[2])
+        raise e
 
 
 def runtest(job, url, tag, args, dargs,