def stack_context(stack_name, create_res=True, convergence=False):
 def stack_delete(test_fn):
  @six.wraps(test_fn)
  def wrapped_test(test_case, *args, **kwargs):
   def create_stack():
    ctx = getattr(test_case, 'ctx', None)
    if (ctx is not None):
     stack = setup_stack(stack_name, ctx, create_res, convergence)
     setattr(test_case, 'stack', stack)
   def delete_stack():
    stack = getattr(test_case, 'stack', None)
    if ((stack is not None) and (stack.id is not None)):
     clean_up_stack(stack, delete_res=create_res)
   create_stack()
   try:
    test_fn(test_case, *args, **kwargs)
   except Exception:
    (exc_class, exc_val, exc_tb) = sys.exc_info()
    try:
     delete_stack()
    finally:
     six.reraise(exc_class, exc_val, exc_tb)
   else:
    delete_stack()
  return wrapped_test
 return stack_delete

def stack_context ( stack_name , create_res = True , convergence = False ) : def stack_delete ( test_fn ) : @ six . wraps ( test_fn ) def wrapped_test ( test_case , * args , ** kwargs ) : def create_stack ( ) : ctx = getattr ( test_case , 'ctx' , None ) if ( ctx is not None ) : stack = setup_stack ( stack_name , ctx , create_res , convergence ) setattr ( test_case , 'stack' , stack ) def delete_stack ( ) : stack = getattr ( test_case , 'stack' , None ) if ( ( stack is not None ) and ( stack . id is not None ) ) : clean_up_stack ( stack , delete_res = create_res ) create_stack ( ) try : test_fn ( test_case , * args , ** kwargs ) except Exception : ( exc_class , exc_val , exc_tb ) = sys . exc_info ( ) try : delete_stack ( ) finally : six . reraise ( exc_class , exc_val , exc_tb ) else : delete_stack ( ) return wrapped_test return stack_delete
decorator for creating and deleting stack .