From: Kevin Benton Date: Mon, 10 Mar 2014 20:49:51 +0000 (+0000) Subject: Stop mock patches by default in base test class X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1dfd65f4cff1133cff45e103083fc3ae3130877b;p=openstack-build%2Fneutron-build.git Stop mock patches by default in base test class Adds a mock.patch.stopall to the base unit test case cleanup routines to stop patches by default in unit tests. This behavior can be overwritten by setting an attribute on the test class if required. Also removes the explicit stops in the Cisco n1kv, VMware, and NEC unit tests to leverage the new automatic cleanup. Closes-Bug: #1290550 Change-Id: Ic642430a765ea8deb07ebd88b619da58a58e0edd --- diff --git a/neutron/tests/base.py b/neutron/tests/base.py index 867357ce7..71b3427e6 100644 --- a/neutron/tests/base.py +++ b/neutron/tests/base.py @@ -23,6 +23,7 @@ import os import eventlet.timeout import fixtures +import mock from oslo.config import cfg import testtools @@ -82,6 +83,7 @@ class BaseTestCase(testtools.TestCase): self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) + self.addCleanup(mock.patch.stopall) self.addCleanup(CONF.reset) if os.environ.get('OS_STDOUT_CAPTURE') in TRUE_STRING: diff --git a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py index 909df2590..40fc4b8e4 100644 --- a/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py +++ b/neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py @@ -172,7 +172,6 @@ class N1kvPluginTestCase(test_plugin.NeutronDbPluginV2TestCase): # Using __name__ to avoid having to enter the full module path. http_patcher = patch(n1kv_client.httplib2.__name__ + ".Http") FakeHttpConnection = http_patcher.start() - self.addCleanup(http_patcher.stop) # Now define the return values for a few functions that may be called # on any instance of the fake HTTP connection class. instance = FakeHttpConnection.return_value @@ -191,13 +190,11 @@ class N1kvPluginTestCase(test_plugin.NeutronDbPluginV2TestCase): get_vsm_hosts_patcher = patch(n1kv_client.__name__ + ".Client._get_vsm_hosts") fake_get_vsm_hosts = get_vsm_hosts_patcher.start() - self.addCleanup(get_vsm_hosts_patcher.stop) fake_get_vsm_hosts.return_value = ["127.0.0.1"] # Return dummy user profiles get_cred_name_patcher = patch(cdb.__name__ + ".get_credential_name") fake_get_cred_name = get_cred_name_patcher.start() - self.addCleanup(get_cred_name_patcher.stop) fake_get_cred_name.return_value = {"user_name": "admin", "password": "admin_password"} diff --git a/neutron/tests/unit/nec/test_nec_plugin.py b/neutron/tests/unit/nec/test_nec_plugin.py index 310c344a2..78a0a7911 100644 --- a/neutron/tests/unit/nec/test_nec_plugin.py +++ b/neutron/tests/unit/nec/test_nec_plugin.py @@ -85,7 +85,8 @@ class NecPluginV2TestCaseBase(object): self.addCleanup(mock.patch.stopall) self._set_nec_ini() self.addCleanup(self._clean_nec_ini) - self.patch_remote_calls(use_stop_each) + # kevinbenton: stopping patches is now handled in base test class + self.patch_remote_calls(use_stop=False) class NecPluginV2TestCase(NecPluginV2TestCaseBase, diff --git a/neutron/tests/unit/test_servicetype.py b/neutron/tests/unit/test_servicetype.py index ec10edeae..f3bdb1c8b 100644 --- a/neutron/tests/unit/test_servicetype.py +++ b/neutron/tests/unit/test_servicetype.py @@ -195,7 +195,6 @@ class ServiceTypeExtensionTestCase(ServiceTypeExtensionTestCaseBase): self._patcher = mock.patch( "neutron.db.servicetype_db.ServiceTypeManager", autospec=True) - self.addCleanup(self._patcher.stop) self.mock_mgr = self._patcher.start() self.mock_mgr.get_instance.return_value = self.mock_mgr.return_value super(ServiceTypeExtensionTestCase, self).setUp() diff --git a/neutron/tests/unit/vmware/extensions/test_maclearning.py b/neutron/tests/unit/vmware/extensions/test_maclearning.py index cb17bf9bd..10a7dc19a 100644 --- a/neutron/tests/unit/vmware/extensions/test_maclearning.py +++ b/neutron/tests/unit/vmware/extensions/test_maclearning.py @@ -76,8 +76,6 @@ class MacLearningDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase): instance.return_value.request.side_effect = self.fc.fake_request cfg.CONF.set_override('metadata_mode', None, 'NSX') self.addCleanup(self.fc.reset_all) - self.addCleanup(self.mock_nsx.stop) - self.addCleanup(patch_sync.stop) self.addCleanup(self.restore_resource_attribute_map) self.addCleanup(cfg.CONF.reset) super(MacLearningDBTestCase, self).setUp(plugin=PLUGIN_NAME, diff --git a/neutron/tests/unit/vmware/test_nsx_plugin.py b/neutron/tests/unit/vmware/test_nsx_plugin.py index c40bd4725..abcb99a7f 100644 --- a/neutron/tests/unit/vmware/test_nsx_plugin.py +++ b/neutron/tests/unit/vmware/test_nsx_plugin.py @@ -358,8 +358,6 @@ class SecurityGroupsTestCase(ext_sg.SecurityGroupDBTestCase): patch_sync.start() instance.return_value.request.side_effect = self.fc.fake_request - self.addCleanup(self.mock_nsx.stop) - self.addCleanup(patch_sync.stop) super(SecurityGroupsTestCase, self).setUp(PLUGIN_NAME)