From 79d9e12ed605ce3e6bcc87e19768962a3097e5e3 Mon Sep 17 00:00:00 2001 From: "Ivan A. Melnikov" Date: Tue, 28 Jan 2014 14:32:31 +0400 Subject: [PATCH] Use addCleanup instead of tearDown in test_sql_persistence TestCase.tearDown() is not called if setUp raises exception, but we have to close backend and release lock before executing other tests. The easiest way to do it is to use addCleanup instead of tearDown for freeing resources. Change-Id: I885bb7d491f4b3ee06a351f5d22087e23804e19b --- .../tests/unit/persistence/test_sql_persistence.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/taskflow/tests/unit/persistence/test_sql_persistence.py b/taskflow/tests/unit/persistence/test_sql_persistence.py index 2306d0d9..ff429757 100644 --- a/taskflow/tests/unit/persistence/test_sql_persistence.py +++ b/taskflow/tests/unit/persistence/test_sql_persistence.py @@ -146,24 +146,17 @@ class BackendPersistenceTestMixin(base.PersistenceTestMixin): """ raise NotImplementedError() - def tearDown(self): - super(BackendPersistenceTestMixin, self).tearDown() - try: - if self.backend is not None: - self.backend.close() - self.backend = None - finally: - self.big_lock.release() - def setUp(self): super(BackendPersistenceTestMixin, self).setUp() self.backend = None self.big_lock.acquire() + self.addCleanup(self.big_lock.release) conf = { 'connection': self._reset_database(), } # Ensure upgraded to the right schema self.backend = impl_sqlalchemy.SQLAlchemyBackend(conf) + self.addCleanup(self.backend.close) with contextlib.closing(self._get_connection()) as conn: conn.upgrade()