diff options
author | Riccardo Pittau <elfosardo@gmail.com> | 2022-10-20 11:36:08 +0200 |
---|---|---|
committer | Riccardo Pittau <elfosardo@gmail.com> | 2022-10-20 13:41:35 +0200 |
commit | a1fe6cb41e6f0a1ed0a43ba5e17745714f206f1f (patch) | |
tree | bc076c7809f2e0776640b28d1d41af33ba92185f | |
parent | c06cb281f99c6b61ceb76bbf816a29a83f0b7d82 (diff) | |
download | ironic-a1fe6cb41e6f0a1ed0a43ba5e17745714f206f1f.tar.gz |
Fix double mock call in glance_service test
Using autospec with the most recent python-mock is more strict and
tests fail if a resource is already mocked out.
For an example see the failing ironic tests in the u-c patch [0]
[0] https://3a727b96f9b24e3543ad-87ad413497532cf6afb3c89ad083bf93.ssl.cf1.rackcdn.com/855711/11/check/cross-ironic-py310/b1d5058/job-output.txt
Change-Id: I1cf0e077417d01a8714bad96b7e90ef786f94b2e
-rw-r--r-- | ironic/tests/unit/common/test_glance_service.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/ironic/tests/unit/common/test_glance_service.py b/ironic/tests/unit/common/test_glance_service.py index 6be0fccd9..327125a81 100644 --- a/ironic/tests/unit/common/test_glance_service.py +++ b/ironic/tests/unit/common/test_glance_service.py @@ -147,22 +147,21 @@ class TestGlanceImageService(base.TestCase): 'os_hash_algo': None, 'os_hash_value': None, } - if not mock._is_instance_mock(self.service.call): - mock.patch.object(self.service, 'call', autospec=True).start() - self.service.call.return_value = image - image_meta = self.service.show(image_id) - self.service.call.assert_called_with('get', image_id) - self.assertEqual(expected, image_meta) + with mock.patch.object(self.service, 'call', autospec=True): + self.service.call.return_value = image + image_meta = self.service.show(image_id) + self.service.call.assert_called_with('get', image_id) + self.assertEqual(expected, image_meta) def test_show_makes_datetimes(self): image_id = uuidutils.generate_uuid() image = self._make_datetime_fixture() - with mock.patch.object(self.service, 'call', return_value=image, - autospec=True): + with mock.patch.object(self.service, 'call', autospec=True): + self.service.call.return_value = image image_meta = self.service.show(image_id) - self.service.call.assert_called_once_with('get', image_id) - self.assertEqual(self.NOW_DATETIME, image_meta['created_at']) - self.assertEqual(self.NOW_DATETIME, image_meta['updated_at']) + self.service.call.assert_called_with('get', image_id) + self.assertEqual(self.NOW_DATETIME, image_meta['created_at']) + self.assertEqual(self.NOW_DATETIME, image_meta['updated_at']) @mock.patch.object(service_utils, 'is_image_active', autospec=True) def test_show_raises_when_no_authtoken_in_the_context(self, @@ -176,11 +175,10 @@ class TestGlanceImageService(base.TestCase): def test_show_raises_when_image_not_active(self): image_id = uuidutils.generate_uuid() image = self._make_fixture(name='image1', id=image_id, status="queued") - if not mock._is_instance_mock(self.service.call): - mock.patch.object(self.service, 'call', autospec=True).start() - self.service.call.return_value = image - self.assertRaises(exception.ImageUnacceptable, - self.service.show, image_id) + with mock.patch.object(self.service, 'call', autospec=True): + self.service.call.return_value = image + self.assertRaises(exception.ImageUnacceptable, + self.service.show, image_id) def test_download_with_retries(self): tries = [0] |