From: Michael Goldish Subject: [KVM-AUTOTEST PATCH 5/7] [RFC] Set the .context attribute for exceptions in _call_test_function() Date: Mon, 3 Jan 2011 20:34:09 +0200 Message-ID: <1294079651-21631-5-git-send-email-mgoldish@redhat.com> References: <1294079651-21631-1-git-send-email-mgoldish@redhat.com> Cc: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:1214 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754742Ab1ACSdk (ORCPT ); Mon, 3 Jan 2011 13:33:40 -0500 In-Reply-To: <1294079651-21631-1-git-send-email-mgoldish@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Before passing exceptions on up, inject context information into them which can later be used by __str__(). Signed-off-by: Michael Goldish --- client/common_lib/test.py | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-) 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, -- 1.7.3.4