Commit 124afe48 by Renzo Lucioni

Make modifies_courseware robust to exceptions raised during tests

Guarantees that SharedModuleStoreTestCase's reset() method is always called, regardless of whether decorated test cases raise exceptions.
parent 3603ede5
...@@ -317,10 +317,20 @@ class SharedModuleStoreTestCase(TestCase): ...@@ -317,10 +317,20 @@ class SharedModuleStoreTestCase(TestCase):
@functools.wraps(f) @functools.wraps(f)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
"""Call the object method, and reset the test case afterwards.""" """Call the object method, and reset the test case afterwards."""
return_val = f(*args, **kwargs) try:
obj = args[0] # Attempt execution of the test.
obj.reset() return_val = f(*args, **kwargs)
return return_val except:
# If the test raises an exception, re-raise it.
raise
else:
# Otherwise, return the test's return value.
return return_val
finally:
# In either case, call SharedModuleStoreTestCase.reset() "on the way out."
# For more, see here: https://docs.python.org/2/tutorial/errors.html#defining-clean-up-actions.
obj = args[0]
obj.reset()
return wrapper return wrapper
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment