Use addCleanup instead of tearDown

We should use addCleanup instead of tearDown because:
- tearDown is executed only if the test succeeds
- cleanups (defined with addCleanup) are executed even if the test fails

This change removes useless tearDown and transforms remaining ones into
addCleanup.

Change-Id: I44bd26dcb5c8456126a35cb807f0bafc772c0ab0
changes/32/427432/3
Cedric Brandily 6 years ago
parent 96bffbf6d2
commit c88debc44f
  1. 5
      neutron/tests/functional/api/test_policies.py
  2. 4
      neutron/tests/functional/pecan_wsgi/__init__.py
  3. 8
      neutron/tests/tempest/api/test_dhcp_ipv6.py
  4. 8
      neutron/tests/unit/api/v2/test_base.py
  5. 9
      neutron/tests/unit/db/test_db_base_plugin_v2.py
  6. 3
      neutron/tests/unit/extensions/test_l3_ext_gw_mode.py
  7. 4
      neutron/tests/unit/extensions/test_portsecurity.py
  8. 5
      neutron/tests/unit/extensions/test_quotasv2.py
  9. 15
      neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py
  10. 3
      neutron/tests/unit/plugins/ml2/test_security_group.py

@ -42,6 +42,7 @@ class APIPolicyTestCase(base.BaseTestCase):
self.extension_path = os.path.abspath(os.path.join(
TEST_PATH, "../../../extensions"))
policy.reset()
self.addCleanup(policy.reset)
def _network_definition(self):
return {'name': 'test_network',
@ -85,7 +86,3 @@ class APIPolicyTestCase(base.BaseTestCase):
tenant_context = context.Context('test_user', 'test_tenant_id', False)
self.assertTrue(self._check_external_router_policy(admin_context))
self.assertTrue(self._check_external_router_policy(tenant_context))
def tearDown(self):
policy.reset()
super(APIPolicyTestCase, self).tearDown()

@ -35,6 +35,4 @@ class FunctionalTest(unittest2.TestCase):
os.path.dirname(__file__),
'config.py'
))
def tearDown(self):
set_config({}, overwrite=True)
self.addCleanup(set_config, {}, overwrite=True)

@ -27,6 +27,10 @@ CONF = config.CONF
class NetworksTestDHCPv6(base.BaseNetworkTest):
_ip_version = 6
def setUp(self):
super(NetworksTestDHCPv6, self).setUp()
self.addCleanup(self._clean_network)
@classmethod
def skip_checks(cls):
msg = None
@ -92,7 +96,3 @@ class NetworksTestDHCPv6(base.BaseNetworkTest):
self.network,
fixed_ips=[{'subnet_id': subnet['id'],
'ip_address': ip}])
def tearDown(self):
self._clean_network()
super(NetworksTestDHCPv6, self).tearDown()

@ -1195,9 +1195,6 @@ class SubresourceTest(base.BaseTestCase):
member=member_actions)
self.api = webtest.TestApp(api)
def tearDown(self):
super(SubresourceTest, self).tearDown()
def test_index_sub_resource(self):
instance = self.plugin.return_value
@ -1494,11 +1491,6 @@ class ExtensionTestCase(base.BaseTestCase):
cfg.CONF.set_override('quota_driver', 'neutron.quota.ConfDriver',
group='QUOTAS')
def tearDown(self):
super(ExtensionTestCase, self).tearDown()
self.api = None
self.plugin = None
def test_extended_create(self):
net_id = _uuid()
tenant_id = _uuid()

@ -163,15 +163,6 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
if ext_mgr:
self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr)
def tearDown(self):
self.api = None
self._deserializers = None
self._skip_native_bulk = None
self._skip_native_pagination = None
self._skip_native_sortin = None
self.ext_api = None
super(NeutronDbPluginV2TestCase, self).tearDown()
def setup_config(self):
# Create the default configurations
args = ['--config-file', base.etcdir('neutron.conf')]

@ -384,9 +384,6 @@ class ExtGwModeIntTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
def restore_l3_attribute_map(self):
l3.RESOURCE_ATTRIBUTE_MAP = self._l3_attribute_map_bk
def tearDown(self):
super(ExtGwModeIntTestCase, self).tearDown()
def _set_router_external_gateway(self, router_id, network_id,
snat_enabled=None,
expected_code=exc.HTTPOk.code,

@ -45,10 +45,6 @@ class PortSecurityTestCase(
self._skip_security_group = ('security-group' not in
plugin_obj.supported_extension_aliases)
def tearDown(self):
super(PortSecurityTestCase, self).tearDown()
self._skip_security_group = None
class PortSecurityTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
securitygroups_db.SecurityGroupDbMixin,

@ -70,11 +70,6 @@ class QuotaExtensionTestCase(testlib_api.WebTestCase):
# resources are registered
router.APIRouter()
def tearDown(self):
self.api = None
self.plugin = None
super(QuotaExtensionTestCase, self).tearDown()
def _test_quota_default_values(self, expected_values):
tenant_id = 'tenant_id1'
env = {'neutron.context': context.Context('', tenant_id)}

@ -625,9 +625,12 @@ class TestDesignateClientKeystoneV3(testtools.TestCase):
super(TestDesignateClientKeystoneV3, self).setUp()
# Register the Password auth plugin options,
# so we can use CONF.set_override
config.cfg.CONF.register_opts(
loading.get_auth_plugin_conf_options('password'),
group='designate')
password_option = loading.get_auth_plugin_conf_options('password')
config.cfg.CONF.register_opts(password_option, group='designate')
self.addCleanup(
config.cfg.CONF.unregister_opts,
password_option, group='designate')
config.cfg.CONF.set_override('url',
self.TEST_URL,
group='designate')
@ -660,12 +663,6 @@ class TestDesignateClientKeystoneV3(testtools.TestCase):
self.password = (
mock.patch.object(driver.password, 'Password').start())
def tearDown(self):
super(TestDesignateClientKeystoneV3, self).tearDown()
config.cfg.CONF.unregister_opts(
loading.get_auth_plugin_conf_options('password'),
group='designate')
def test_insecure_client(self):
config.cfg.CONF.set_override('insecure',
True,

@ -44,9 +44,6 @@ class Ml2SecurityGroupsTestCase(test_sg.SecurityGroupDBTestCase):
self.useFixture(tools.AttributeMapMemento())
super(Ml2SecurityGroupsTestCase, self).setUp('ml2')
def tearDown(self):
super(Ml2SecurityGroupsTestCase, self).tearDown()
class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase,
test_sg.TestSecurityGroups,

Loading…
Cancel
Save