]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Stop mock patches by default in base test class
authorKevin Benton <blak111@gmail.com>
Mon, 10 Mar 2014 20:49:51 +0000 (20:49 +0000)
committerKevin Benton <blak111@gmail.com>
Wed, 12 Mar 2014 02:20:16 +0000 (02:20 +0000)
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

neutron/tests/base.py
neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py
neutron/tests/unit/nec/test_nec_plugin.py
neutron/tests/unit/test_servicetype.py
neutron/tests/unit/vmware/extensions/test_maclearning.py
neutron/tests/unit/vmware/test_nsx_plugin.py

index 867357ce75ae444fa30cbf9aec0c1118b24df4f5..71b3427e67f6ffc19e00ac17bfc6a108cde70e6f 100644 (file)
@@ -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:
index 909df25905a23c22ba48de36538cb6a38bd6dc19..40fc4b8e42f72c681321513ffaa3ee7e23c4109d 100644 (file)
@@ -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"}
 
index 310c344a2b26d1126cfbec4cf28952fa334b3d5d..78a0a7911ce3546662aefa58f6a4184e8084a200 100644 (file)
@@ -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,
index ec10edeae3ecbc20807b1c9cda42aca4eaefac24..f3bdb1c8bfbd7831b41a97ba16426894340b28aa 100644 (file)
@@ -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()
index cb17bf9bd86b538d8b05cdc7bbc0196cb00f2e76..10a7dc19a471c6bcbe27823f15aac8dfd889dc9d 100644 (file)
@@ -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,
index c40bd47251542bec7165ede31a258751257e7389..abcb99a7f7468258f298b73073567eaa9379dee4 100644 (file)
@@ -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)