tests: create common resources at class init time

This should save a bit of time.

Change-Id: Ia43ee874f5d55e93fe96f2c5a352a4bd01912407
This commit is contained in:
Julien Danjou 2016-05-13 10:10:06 +02:00
parent ee2eb67b99
commit f181d4b2a6
2 changed files with 11 additions and 7 deletions

View File

@ -32,6 +32,7 @@ _RUN = False
def _setup_test_app(): def _setup_test_app():
t = test_rest.RestTest() t = test_rest.RestTest()
t.auth = True t.auth = True
t.setUpClass()
t.setUp() t.setUp()
return t.app return t.app

View File

@ -374,8 +374,9 @@ class TestCase(base.BaseTestCase):
return os.path.join(root, project_file) return os.path.join(root, project_file)
return root return root
def setUp(self): @classmethod
super(TestCase, self).setUp() def setUpClass(self):
super(TestCase, self).setUpClass()
self.conf = service.prepare_service([], self.conf = service.prepare_service([],
default_config_files=[]) default_config_files=[])
self.conf.set_override('policy_file', self.conf.set_override('policy_file',
@ -410,6 +411,13 @@ class TestCase(base.BaseTestCase):
except indexer.ArchivePolicyAlreadyExists: except indexer.ArchivePolicyAlreadyExists:
pass pass
self.conf.set_override(
'driver',
os.getenv("GNOCCHI_TEST_STORAGE_DRIVER", "null"),
'storage')
def setUp(self):
super(TestCase, self).setUp()
if swexc: if swexc:
self.useFixture(mockpatch.Patch( self.useFixture(mockpatch.Patch(
'swiftclient.client.Connection', 'swiftclient.client.Connection',
@ -418,11 +426,6 @@ class TestCase(base.BaseTestCase):
self.useFixture(mockpatch.Patch('gnocchi.storage.ceph.rados', self.useFixture(mockpatch.Patch('gnocchi.storage.ceph.rados',
FakeRadosModule())) FakeRadosModule()))
self.conf.set_override(
'driver',
os.getenv("GNOCCHI_TEST_STORAGE_DRIVER", "null"),
'storage')
if self.conf.storage.driver == 'file': if self.conf.storage.driver == 'file':
tempdir = self.useFixture(fixtures.TempDir()) tempdir = self.useFixture(fixtures.TempDir())
self.conf.set_override('file_basepath', self.conf.set_override('file_basepath',