I have some code which represents a test case within a proprietary testing framework that looks something like this:
def test_alarm(self):
self.setup_some_test_data()
try:
self.send_alarm_message()
except:
print "Unexpected error:", sys.exc_info()
finally:
self.teardown_some_test_data()
I've been told to drop the print as it's not necessary and the test framework will in any case catch any exceptions, which is preferred to catching them here, but I still need to always clear the data down, as in the finally
block.
Do I just drop the except
block entirely? Alternatively, how, can I structure the code to effectively have an empty except
block and retain the finally
? Is this good practice in Python or is there a better way to do it?
Edit Note that I did try just dropping the except
block entirely, and I had no obvious run-time problems, though since exceptions are unlikely in the the call to send_alarm_message()
, it was unclear to me how it would work if an exception was thrown or whether this was considered good practice by the Python community.