diff --git a/neutronclient/tests/unit/test_cli20.py b/neutronclient/tests/unit/test_cli20.py index 7a0747b38..19bd29708 100644 --- a/neutronclient/tests/unit/test_cli20.py +++ b/neutronclient/tests/unit/test_cli20.py @@ -18,7 +18,7 @@ import contextlib import itertools import sys -import fixtures +import mock from mox3 import mox from oslo_utils import encodeutils from oslotest import base @@ -192,13 +192,14 @@ class CLITestV20Base(base.BaseTestCase): self.mox = mox.Mox() self.endurl = ENDURL self.fake_stdout = FakeStdout() - self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.fake_stdout)) - self.useFixture(fixtures.MonkeyPatch( - 'neutronclient.neutron.v2_0.find_resourceid_by_name_or_id', - self._find_resourceid)) - self.useFixture(fixtures.MonkeyPatch( - 'neutronclient.neutron.v2_0.find_resourceid_by_id', - self._find_resourceid)) + + self.addCleanup(mock.patch.stopall) + mock.patch('sys.stdout', new=self.fake_stdout).start() + mock.patch('neutronclient.neutron.v2_0.find_resourceid_by_name_or_id', + new=self._find_resourceid).start() + mock.patch('neutronclient.neutron.v2_0.find_resourceid_by_id', + new=self._find_resourceid).start() + self.client = client.Client(token=TOKEN, endpoint_url=self.endurl) self.client.format = self.format diff --git a/neutronclient/tests/unit/test_client_extension.py b/neutronclient/tests/unit/test_client_extension.py index 0fccd5e84..973f80068 100644 --- a/neutronclient/tests/unit/test_client_extension.py +++ b/neutronclient/tests/unit/test_client_extension.py @@ -34,15 +34,9 @@ class CLITestV20ExtensionJSON(test_cli20.CLITestV20Base): self._mock_extension_loading() super(CLITestV20ExtensionJSON, self).setUp(plurals={'tags': 'tag'}) - def _create_patch(self, name, func=None): - patcher = mock.patch(name) - thing = patcher.start() - self.addCleanup(patcher.stop) - return thing - def _mock_extension_loading(self): ext_pkg = 'neutronclient.common.extension' - contrib = self._create_patch(ext_pkg + '._discover_via_entry_points') + contrib = mock.patch(ext_pkg + '._discover_via_entry_points').start() contrib.return_value = [("_fox_sockets", fox_sockets)] return contrib @@ -134,15 +128,9 @@ class CLITestV20ExtensionJSONAlternatePlurals(test_cli20.CLITestV20Base): self._mock_extension_loading() super(CLITestV20ExtensionJSONAlternatePlurals, self).setUp() - def _create_patch(self, name, func=None): - patcher = mock.patch(name) - thing = patcher.start() - self.addCleanup(patcher.stop) - return thing - def _mock_extension_loading(self): ext_pkg = 'neutronclient.common.extension' - contrib = self._create_patch(ext_pkg + '._discover_via_entry_points') + contrib = mock.patch(ext_pkg + '._discover_via_entry_points').start() ip_address = mock.MagicMock() ip_address.IPAddress = self.IPAddress ip_address.IPAddressesList = self.IPAddressesList @@ -193,15 +181,9 @@ class CLITestV20ExtensionJSONChildResource(test_cli20.CLITestV20Base): self._mock_extension_loading() super(CLITestV20ExtensionJSONChildResource, self).setUp() - def _create_patch(self, name, func=None): - patcher = mock.patch(name) - thing = patcher.start() - self.addCleanup(patcher.stop) - return thing - def _mock_extension_loading(self): ext_pkg = 'neutronclient.common.extension' - contrib = self._create_patch(ext_pkg + '._discover_via_entry_points') + contrib = mock.patch(ext_pkg + '._discover_via_entry_points').start() child = mock.MagicMock() child.Child = self.Child child.ChildrenList = self.ChildrenList