Fix mock for 'autospec' and 'new' together

mock does not accept 'autospec' and 'new' attributes
together to create mock object for tests. If autospec
is True the mock object is created using create_autospec()
and pass the keyword args to called function.

If both are passed then it start failing with oslotest 4.4.0
which is migrated to unittest.mock.
- https://d088a63e8edc60022939-485bd9eedc766dc9e54cbbb4001038bd.ssl.cf5.rackcdn.com/739330/1/check/cross-nova-py36/843ec44/testr_results.html

Creating mock with autospec only to fix this test to make
nova pass for oslo 4.4.0 so that requirement
can constraint oslotest to 4.4.0 (needed-by patch).

Change-Id: I9d6d97563114380f9a7549f08cede4b808352a3e
Needed-By: https://review.opendev.org/#/c/739531/
This commit is contained in:
Ghanshyam Mann 2020-07-04 18:55:07 -05:00
parent 43802e5170
commit 2ee9ad2516
1 changed files with 3 additions and 3 deletions

View File

@ -59,10 +59,10 @@ class FilterSchedulerTestCase(test.NoDBTestCase):
@mock.patch.object(host_manager.HostManager, '_init_aggregates',
new=mock.Mock())
@mock.patch('nova.scheduler.client.report.SchedulerReportClient',
autospec=True, new=mock.Mock())
autospec=True)
@mock.patch('nova.scheduler.client.query.SchedulerQueryClient',
autospec=True, new=mock.Mock())
def setUp(self):
autospec=True)
def setUp(self, mock_sch_query, mock_sch_report):
super(FilterSchedulerTestCase, self).setUp()
self.driver = filter_scheduler.FilterScheduler()