From 9cead1a7e8bd44e69d9fee881477231b2b45fbe1 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Fri, 1 Feb 2013 11:23:33 +0000 Subject: [PATCH] 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 --- heat/tests/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 -- 2.45.2