diff options
author | Ihar Hrachyshka <ihrachys@redhat.com> | 2016-05-18 09:59:50 +0200 |
---|---|---|
committer | Ihar Hrachyshka <ihrachys@redhat.com> | 2016-05-18 18:00:40 +0200 |
commit | 8570dd1f0ae0bb2277535a9f92d592dfa9bf3d34 (patch) | |
tree | 80e02f0baa80731c4e7258ecdd48d4c79dd2b766 | |
parent | 1575d92ba5be356e34df34513675299198074c95 (diff) | |
download | python-neutronclient-8570dd1f0ae0bb2277535a9f92d592dfa9bf3d34.tar.gz |
Switched from fixtures.MonkeyPatch to mock.patch
fixtures 2.0.0 released a new version of monkey patching fixture that
triggered issues with patching out class methods in stable/liberty.
We already stopped relying on fixtures for monkey patching in neutron:
I58d7a750e263e4af54589ace07ac00bec34b553a and switched to mock there.
fixtures library is still used for other fixtures, so the dependency
stays. Mock library is already in the dependency list, so
test-requirements.txt is not touched.
Local changes:
- also convert get_attr_metadata mock to ... mock. :) In Mitaka+, the
mock was not needed at all, so we removed it there. For Liberty, we
need to convert it instead.
Also include a version cap for keystoneclient since 3.0.0 breaks the
gate.
Change-Id: If43f3e08ee2235f96b0e5069b0df798a1acb48ea
Closes-Bug: #1583029
(cherry picked from commit 35ce1a512a92147b0402c5eed9b2aeb1f0f13d87)
-rw-r--r-- | neutronclient/tests/unit/test_cli20.py | 22 | ||||
-rw-r--r-- | neutronclient/tests/unit/test_client_extension.py | 24 | ||||
-rw-r--r-- | requirements.txt | 8 |
3 files changed, 18 insertions, 36 deletions
diff --git a/neutronclient/tests/unit/test_cli20.py b/neutronclient/tests/unit/test_cli20.py index 0ceca4a..30f9319 100644 --- a/neutronclient/tests/unit/test_cli20.py +++ b/neutronclient/tests/unit/test_cli20.py @@ -19,7 +19,7 @@ import copy import itertools import sys -import fixtures +import mock from mox3 import mox from oslo_utils import encodeutils from oslotest import base @@ -208,16 +208,16 @@ 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.useFixture(fixtures.MonkeyPatch( - 'neutronclient.v2_0.client.Client.get_attr_metadata', - self._get_attr_metadata)) + + 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() + mock.patch('neutronclient.v2_0.client.Client.get_attr_metadata', + new=self._get_attr_metadata).start() + self.client = client.Client(token=TOKEN, endpoint_url=self.endurl) def register_non_admin_status_resource(self, resource_name): diff --git a/neutronclient/tests/unit/test_client_extension.py b/neutronclient/tests/unit/test_client_extension.py index 8684c08..e383389 100644 --- a/neutronclient/tests/unit/test_client_extension.py +++ b/neutronclient/tests/unit/test_client_extension.py @@ -31,15 +31,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 @@ -126,15 +120,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 @@ -185,15 +173,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 diff --git a/requirements.txt b/requirements.txt index 279f605..580165d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,14 +3,14 @@ # process, which may cause wedges in the gate later. pbr>=1.6 argparse -cliff>=1.14.0 # Apache-2.0 +cliff!=1.16.0,!=1.17.0,>=1.14.0 # Apache-2.0 iso8601>=0.1.9 netaddr!=0.7.16,>=0.7.12 oslo.i18n>=1.5.0 # Apache-2.0 oslo.serialization>=1.4.0 # Apache-2.0 oslo.utils!=2.6.0,>=2.0.0 # Apache-2.0 -requests!=2.8.0,>=2.5.2 -python-keystoneclient!=1.8.0,>=1.6.0 +requests!=2.8.0,!=2.9.0,>=2.5.2 +python-keystoneclient!=1.8.0,<3.0.0,>=1.6.0 simplejson>=2.2.0 six>=1.9.0 -Babel>=1.3 +Babel!=2.3.0,!=2.3.1,!=2.3.2,!=2.3.3,>=1.3 # BSD |