From: Zane Bitter Date: Fri, 3 May 2013 13:57:57 +0000 (+0200) Subject: Fix error reporting in @stack_delete_after unit tests X-Git-Tag: 2014.1~649 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0326c16c11ddea21ba3c8fc4cb73eca93566c706;p=openstack-build%2Fheat-build.git Fix error reporting in @stack_delete_after unit tests If a unit test decorated with @stack_delete_after (to ensure that a stack being tested is cleaned up) fails in such a way that the stack cannot be cleaned up, the original error was suppressed, making debugging very difficult. In this case, we should re-raise the original exception. Change-Id: I2b0c326f819cd8a6bc772fe52deb14fb1c41bf93 --- diff --git a/heat/tests/utils.py b/heat/tests/utils.py index 3b5d5ffd..583d8939 100644 --- a/heat/tests/utils.py +++ b/heat/tests/utils.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import sys +import functools from testtools import skipIf @@ -40,15 +42,24 @@ def stack_delete_after(test_fn): Decorator which calls test class self.stack.delete() to ensure tests clean up their stacks regardless of test success/failure """ - def wrapped_test(test_cls): + @functools.wraps(test_fn) + def wrapped_test(test_case, *args, **kwargs): + def delete_stack(): + stack = getattr(test_case, 'stack', None) + if stack is not None and stack.id is not None: + stack.delete() + try: - test_fn(test_cls) - finally: + test_fn(test_case, *args, **kwargs) + except: + exc_class, exc_val, exc_tb = sys.exc_info() try: - if test_cls.stack.id is not None: - test_cls.stack.delete() - except AttributeError: - pass + delete_stack() + finally: + raise exc_class, exc_val, exc_tb + else: + delete_stack() + return wrapped_test