From: Steven Hardy Date: Fri, 1 Feb 2013 11:23:33 +0000 (+0000) Subject: heat tests : Add utility decorator for deleting stacks X-Git-Tag: 2014.1~946 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9cead1a7e8bd44e69d9fee881477231b2b45fbe1;p=openstack-build%2Fheat-build.git heat tests : Add utility decorator for deleting stacks Add decorator function which allows test functions to be wrapped such that if they create a stack (and it is stored in the testcase class as self.stack) it is always deleted on test exit, regardless of test success/failure Change-Id: Ibde9a2cee08448e3f24c6b7efbfe756a01f9eccc Signed-off-by: Steven Hardy --- diff --git a/heat/tests/utils.py b/heat/tests/utils.py index 05533585..b2a70556 100644 --- a/heat/tests/utils.py +++ b/heat/tests/utils.py @@ -62,3 +62,18 @@ class skip_unless(object): _skipper.__name__ = func.__name__ _skipper.__doc__ = func.__doc__ return _skipper + + +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): + print "Running test", test_fn.__name__ + try: + test_fn(test_cls) + finally: + test_cls.stack.delete() + print "Exited", test_fn.__name__ + return wrapped_test