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. Change-Id: If43f3e08ee2235f96b0e5069b0df798a1acb48ea Closes-Bug: #1583029
This commit is contained in:
parent
9e4f826166
commit
35ce1a512a
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue