Merge "Fix mock.patch usage in unit tests"

This commit is contained in:
Zuul
2018-09-13 16:50:42 +00:00
committed by Gerrit Code Review
4 changed files with 14 additions and 8 deletions
+2
View File
@@ -8373,9 +8373,11 @@ class ComputeAPITestCase(BaseTestCase):
'schedule_and_build_instances',
autospec=True)
self.schedule_and_build_instances_mock = _patch.start()
self.addCleanup(_patch.stop)
_patch = mock.patch.object(self.compute_api.compute_task_api,
'rebuild_instance', autospec=True)
self.rebuild_instance_mock = _patch.start()
self.addCleanup(_patch.stop)
# Assume that we're always OK for network quota.
def fake_validate_networks(context, requested_networks, num_instances):
+4 -2
View File
@@ -33,6 +33,8 @@ def patch_pci_whitelist(f):
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
patcher = fake_pci_whitelist()
f(self, *args, **kwargs)
patcher.stop()
try:
f(self, *args, **kwargs)
finally:
patcher.stop()
return wrapper
@@ -1058,9 +1058,10 @@ class TestSetAndClearAllocations(SchedulerReportClientTestCase):
super(TestSetAndClearAllocations, self).setUp()
# We want to reuse the mock throughout the class, but with
# different return values.
self.mock_post = mock.patch(
'nova.scheduler.client.report.SchedulerReportClient.post').start()
self.addCleanup(self.mock_post.stop)
patcher = mock.patch(
'nova.scheduler.client.report.SchedulerReportClient.post')
self.mock_post = patcher.start()
self.addCleanup(patcher.stop)
self.mock_post.return_value.status_code = 204
self.rp_uuid = mock.sentinel.rp
self.consumer_uuid = mock.sentinel.consumer
+4 -3
View File
@@ -989,10 +989,11 @@ class CinderClientTestCase(test.NoDBTestCase):
self.ctxt = context.RequestContext('fake-user', 'fake-project')
# Mock out the keystoneauth stuff.
self.mock_session = mock.Mock(autospec=session.Session)
load_session = mock.patch('keystoneauth1.loading.'
patcher = mock.patch('keystoneauth1.loading.'
'load_session_from_conf_options',
return_value=self.mock_session).start()
self.addCleanup(load_session.stop)
return_value=self.mock_session)
patcher.start()
self.addCleanup(patcher.stop)
@mock.patch('cinderclient.client.get_volume_api_from_url',
return_value='3')