From 60a28f35bf7530ccff39b1f0ea849d0439f49d70 Mon Sep 17 00:00:00 2001 From: Julia Varlamova Date: Thu, 27 Feb 2014 18:31:29 +0400 Subject: [PATCH] Replace tearDown with addCleanup - Part 5 Replace tearDown with addCleanup in: - cinder/test.py - cinder/tests/test_migrations.py Remove empty tearDown methods from: - cinder/tests/test_hp3par.py - cinder/tests/test_hplefthand.py - cinder/tests/test_ibmnas.py since it does not add any functionality (and empty setUp methods as well). Infra team has indicated that tearDown should not be used and should be replaced with addCleanup in all places. Implements blueprint replace-teardown-with-addcleanup Change-Id: Id2fdd3e2e1ab8458083697b6ea6714ca019fd00a --- cinder/test.py | 4 ++-- cinder/tests/test_hp3par.py | 12 ------------ cinder/tests/test_hplefthand.py | 9 --------- cinder/tests/test_ibmnas.py | 3 --- cinder/tests/test_migrations.py | 5 +---- 5 files changed, 3 insertions(+), 30 deletions(-) diff --git a/cinder/test.py b/cinder/test.py index 2f6b887df..b394f4102 100644 --- a/cinder/test.py +++ b/cinder/test.py @@ -173,6 +173,7 @@ class TestCase(testtools.TestCase): self.addCleanup(self.stubs.UnsetAll) self.addCleanup(self.stubs.SmartUnsetAll) self.addCleanup(self.mox.VerifyAll) + self.addCleanup(self._common_cleanup) self.injected = [] self._services = [] @@ -182,7 +183,7 @@ class TestCase(testtools.TestCase): # This will be cleaned up by the NestedTempfile fixture CONF.set_override('lock_path', tempfile.mkdtemp()) - def tearDown(self): + def _common_cleanup(self): """Runs after each test method to tear down test environment.""" # Stop any timers @@ -204,7 +205,6 @@ class TestCase(testtools.TestCase): # suite for key in [k for k in self.__dict__.keys() if k[0] != '_']: del self.__dict__[key] - super(TestCase, self).tearDown() def flags(self, **kw): """Override CONF variables for a test.""" diff --git a/cinder/tests/test_hp3par.py b/cinder/tests/test_hp3par.py index 119f6c404..4ad126cfb 100644 --- a/cinder/tests/test_hp3par.py +++ b/cinder/tests/test_hp3par.py @@ -934,12 +934,6 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase): ['0987654321234', '123456789000987'], }}} - def setUp(self): - super(TestHP3PARFCDriver, self).setUp() - - def tearDown(self): - super(TestHP3PARFCDriver, self).tearDown() - def setup_driver(self, config=None, mock_conf=None): self.ctxt = context.get_admin_context() @@ -1264,12 +1258,6 @@ class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase): 'target_lun': TARGET_LUN, 'target_portal': '1.1.1.2:1234'}} - def setUp(self): - super(TestHP3PARISCSIDriver, self).setUp() - - def tearDown(self): - super(TestHP3PARISCSIDriver, self).tearDown() - def setup_driver(self, config=None, mock_conf=None): self.ctxt = context.get_admin_context() diff --git a/cinder/tests/test_hplefthand.py b/cinder/tests/test_hplefthand.py index 040ad86bf..654a5ddc1 100644 --- a/cinder/tests/test_hplefthand.py +++ b/cinder/tests/test_hplefthand.py @@ -340,9 +340,6 @@ class TestHPLeftHandCLIQISCSIDriver(HPLeftHandBaseDriver, test.TestCase): 'iqn.2003-10.com.lefthandnetworks:group01:25366:fakev', 'volume_id': self.volume_id} - def tearDown(self): - super(TestHPLeftHandCLIQISCSIDriver, self).tearDown() - def default_mock_conf(self): mock_conf = mock.Mock() @@ -601,12 +598,6 @@ class TestHPLeftHandRESTISCSIDriver(HPLeftHandBaseDriver, test.TestCase): mock.call.getClusterByName('CloudCluster1'), mock.call.getCluster(1)] - def setUp(self): - super(TestHPLeftHandRESTISCSIDriver, self).setUp() - - def tearDown(self): - super(TestHPLeftHandRESTISCSIDriver, self).tearDown() - def default_mock_conf(self): mock_conf = mock.Mock() diff --git a/cinder/tests/test_ibmnas.py b/cinder/tests/test_ibmnas.py index 8105eb61a..bff55d3d0 100644 --- a/cinder/tests/test_ibmnas.py +++ b/cinder/tests/test_ibmnas.py @@ -79,9 +79,6 @@ class IBMNASDriverTestCase(test.TestCase): self.context.user_id = 'fake' self.context.project_id = 'fake' - def tearDown(self): - super(IBMNASDriverTestCase, self).tearDown() - def _set_flag(self, flag, value): group = self._driver.configuration.config_group self._driver.configuration.set_override(flag, value, group) diff --git a/cinder/tests/test_migrations.py b/cinder/tests/test_migrations.py index bba727a17..d3ec208f3 100644 --- a/cinder/tests/test_migrations.py +++ b/cinder/tests/test_migrations.py @@ -162,13 +162,10 @@ class TestMigrations(test.TestCase): # We start each test case with a completely blank slate. self._reset_databases() - def tearDown(self): - # We destroy the test data store between each test case, # and recreate it, which ensures that we have no side-effects # from the tests - self._reset_databases() - super(TestMigrations, self).tearDown() + self.addCleanup(self._reset_databases) def _reset_databases(self): def execute_cmd(cmd=None): -- 2.45.2