Use ConfigFixture to ensure config settings are reverted
Update the test configuration management code to use a ConfigFixture so that configuration changes are rolled back at the end of each test. Also fix the initialization order in TestSwiftParams to ensure that the base class is configured before local customizations are applied. Change-Id: I27620e3d4caf95e2c75fbf2cf2716ae1337030c7
This commit is contained in:
parent
8c3a1e210e
commit
ccf2922988
|
@ -22,11 +22,11 @@ from glance.tests.unit import base
|
|||
class TestSwiftParams(base.IsolatedUnitTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSwiftParams, self).setUp()
|
||||
conf_file = "glance-swift.conf"
|
||||
test_dir = self.useFixture(fixtures.TempDir()).path
|
||||
self.swift_config_file = self._copy_data_file(conf_file, test_dir)
|
||||
self.config(swift_store_config_file=self.swift_config_file)
|
||||
super(TestSwiftParams, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestSwiftParams, self).tearDown()
|
||||
|
|
|
@ -25,6 +25,7 @@ import subprocess
|
|||
|
||||
import fixtures
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as cfg_fixture
|
||||
from oslo_log import log
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import timeutils
|
||||
|
@ -64,6 +65,8 @@ class BaseTestCase(testtools.TestCase):
|
|||
def setUp(self):
|
||||
super(BaseTestCase, self).setUp()
|
||||
|
||||
self._config_fixture = self.useFixture(cfg_fixture.Config())
|
||||
|
||||
# NOTE(bcwaldon): parse_args has to be called to register certain
|
||||
# command-line options - specifically we need config_dir for
|
||||
# the following policy tests
|
||||
|
@ -122,9 +125,7 @@ class BaseTestCase(testtools.TestCase):
|
|||
All overrides are automatically cleared at the end of the current
|
||||
test by the fixtures cleanup process.
|
||||
"""
|
||||
group = kw.pop('group', None)
|
||||
for k, v in six.iteritems(kw):
|
||||
CONF.set_override(k, v, group)
|
||||
self._config_fixture.config(**kw)
|
||||
|
||||
|
||||
class requires(object):
|
||||
|
|
Loading…
Reference in New Issue