Merge "Favor addCleanup() over tearDown()"

This commit is contained in:
Jenkins 2014-06-20 11:25:46 +00:00 committed by Gerrit Code Review
commit 1bda6212d2
4 changed files with 7 additions and 35 deletions

View File

@ -48,6 +48,9 @@ class FunctionalTest(base.DbTestCase):
'auth_enable': False
}
})
self.addCleanup(pecan.set_config, {}, overwrite=True)
self.addCleanup(cfg.CONF.set_default, 'auth_enable', False,
group='pecan')
# make sure the api get the correct context.
self.patch_ctx = mock.patch('mistral.context.context_from_headers')
@ -55,10 +58,6 @@ class FunctionalTest(base.DbTestCase):
self.mock_ctx.return_value = self.ctx
self.addCleanup(self.patch_ctx.stop)
def tearDown(self):
super(FunctionalTest, self).tearDown()
pecan.set_config({}, overwrite=True)
def assertNotFound(self, url):
try:
self.app.get(url, headers={'Accept': 'application/json'})

View File

@ -76,12 +76,6 @@ class TestKeystoneMiddleware(base.FunctionalTest):
}
})
def tearDown(self):
# By default, unit tests in Mistral has auth disabled and will fail
# if this option is not reset to False after this test is completed.
cfg.CONF.set_default('auth_enable', False, group='pecan')
super(TestKeystoneMiddleware, self).tearDown()
@mock.patch.object(
auth_token.AuthProtocol, '_get_user_token_from_header',
mock.MagicMock(return_value=''))

View File

@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import pkg_resources as pkg
import sys
import tempfile
@ -62,16 +61,6 @@ def get_fake_transport():
class BaseTest(base.BaseTestCase):
def setUp(self):
super(BaseTest, self).setUp()
# TODO(everyone): add whatever is needed for all Mistral tests in here
def tearDown(self):
super(BaseTest, self).tearDown()
# TODO(everyone): add whatever is needed for all Mistral tests in here
def assertListEqual(self, l1, l2):
if tuple(sys.version_info)[0:2] < (2, 7):
# for python 2.6 compatibility
@ -116,10 +105,11 @@ class BaseTest(base.BaseTestCase):
class DbTestCase(BaseTest):
def setUp(self):
super(DbTestCase, self).setUp()
self.db_fd, self.db_path = tempfile.mkstemp()
_db_fd, self.db_path = tempfile.mkstemp()
cfg.CONF.set_default('connection', 'sqlite:///' + self.db_path,
group='database')
db_api.setup_db()
self.addCleanup(db_api.drop_db)
self.ctx = auth_context.MistralContext(user_id='1-2-3-4',
project_id='5-6-7-8',
@ -129,12 +119,6 @@ class DbTestCase(BaseTest):
auth_context.set_ctx(self.ctx)
self.addCleanup(auth_context.set_ctx, None)
def tearDown(self):
super(DbTestCase, self).tearDown()
db_api.drop_db()
os.close(self.db_fd)
os.unlink(self.db_path)
def is_db_session_open(self):
return db_api._get_thread_local_session() is not None

View File

@ -48,14 +48,9 @@ class TestTransport(base.EngineTestCase):
# Run the Engine and Executor in the background.
self.en_thread = eventlet.spawn(launch.launch_engine, self.transport)
self.addCleanup(self.en_thread.kill)
self.ex_thread = eventlet.spawn(launch.launch_executor, self.transport)
def tearDown(self):
# Stop the Engine and the Executor.
self.en_thread.kill()
self.ex_thread.kill()
super(TestTransport, self).tearDown()
self.addCleanup(self.ex_thread.kill)
@mock.patch.object(
db_api, 'workbook_get',