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
import eventlet.timeout
import fixtures
+import mock
from oslo.config import cfg
import testtools
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:
# 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
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"}
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,
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()
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,
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)