From c64c11a5efded1c3fda62956f18c6d65e8bd2419 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Cuong Date: Tue, 30 May 2017 02:00:45 -0400 Subject: [PATCH] Using fixtures instead of deprecated mockpatch module This module mockpatch of oslotest is deprecated since version 1.13 and may be removed in version 2.0. Use fixtures.Mock* classes instead[1] [1]https://docs.openstack.org/developer/oslotest/api/oslotest.mockpatch.html#module-oslotest.mockpatch Change-Id: Ic5ce69409cc690b08cce974fc86e072fbd9240ca --- .../openstack/services/image/test_glance_v1.py | 4 ++-- .../openstack/services/image/test_glance_v2.py | 4 ++-- tests/unit/plugins/openstack/test_scenario.py | 7 +++---- tests/unit/test.py | 14 +++++++------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/unit/plugins/openstack/services/image/test_glance_v1.py b/tests/unit/plugins/openstack/services/image/test_glance_v1.py index 0c8aeaec12..2de460b04f 100755 --- a/tests/unit/plugins/openstack/services/image/test_glance_v1.py +++ b/tests/unit/plugins/openstack/services/image/test_glance_v1.py @@ -15,13 +15,13 @@ import tempfile import ddt +import fixtures import mock from rally.plugins.openstack.services.image import glance_v1 from rally.plugins.openstack.services.image import image from tests.unit import test -from oslotest import mockpatch PATH = ("rally.plugins.openstack.services.image.glance_common." "UnifiedGlanceMixin._unify_image") @@ -38,7 +38,7 @@ class GlanceV1ServiceTestCase(test.TestCase): self.name_generator = mock.MagicMock() self.service = glance_v1.GlanceV1Service( self.clients, name_generator=self.name_generator) - self.mock_wait_for_status = mockpatch.Patch( + self.mock_wait_for_status = fixtures.MockPatch( "rally.task.utils.wait_for_status") self.useFixture(self.mock_wait_for_status) diff --git a/tests/unit/plugins/openstack/services/image/test_glance_v2.py b/tests/unit/plugins/openstack/services/image/test_glance_v2.py index 67324feda6..fea700a5a1 100755 --- a/tests/unit/plugins/openstack/services/image/test_glance_v2.py +++ b/tests/unit/plugins/openstack/services/image/test_glance_v2.py @@ -15,12 +15,12 @@ import tempfile import ddt +import fixtures import mock from rally.plugins.openstack.services.image import glance_v2 from tests.unit import test -from oslotest import mockpatch PATH = ("rally.plugins.openstack.services.image.glance_common." "UnifiedGlanceMixin._unify_image") @@ -37,7 +37,7 @@ class GlanceV2ServiceTestCase(test.TestCase): self.name_generator = mock.MagicMock() self.service = glance_v2.GlanceV2Service( self.clients, name_generator=self.name_generator) - self.mock_wait_for_status = mockpatch.Patch( + self.mock_wait_for_status = fixtures.MockPatch( "rally.task.utils.wait_for_status") self.useFixture(self.mock_wait_for_status) diff --git a/tests/unit/plugins/openstack/test_scenario.py b/tests/unit/plugins/openstack/test_scenario.py index 3806273331..96d00baf61 100644 --- a/tests/unit/plugins/openstack/test_scenario.py +++ b/tests/unit/plugins/openstack/test_scenario.py @@ -12,10 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. - import ddt +import fixtures import mock -from oslotest import mockpatch + from rally.plugins.openstack.credential import OpenStackCredential from rally.plugins.openstack import scenario as base_scenario from tests.unit import test @@ -37,8 +37,7 @@ CREDENTIAL_WITH_HMAC = OpenStackCredential( class OpenStackScenarioTestCase(test.TestCase): def setUp(self): super(OpenStackScenarioTestCase, self).setUp() - self.osclients = mockpatch.Patch( - "rally.osclients.Clients") + self.osclients = fixtures.MockPatch("rally.osclients.Clients") self.useFixture(self.osclients) self.context = test.get_test_context() self.context.update({"foo": "bar"}) diff --git a/tests/unit/test.py b/tests/unit/test.py index d7c7b026b5..98b7e9d622 100644 --- a/tests/unit/test.py +++ b/tests/unit/test.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +import fixtures import os import uuid import mock from oslo_config import fixture from oslotest import base -from oslotest import mockpatch from rally.common import db from rally import plugins @@ -119,15 +119,15 @@ class ScenarioTestCase(TestCase): def setUp(self): super(ScenarioTestCase, self).setUp() if self.patch_benchmark_utils: - self.mock_resource_is = mockpatch.Patch( + self.mock_resource_is = fixtures.MockPatch( self.benchmark_utils + ".resource_is") - self.mock_get_from_manager = mockpatch.Patch( + self.mock_get_from_manager = fixtures.MockPatch( self.benchmark_utils + ".get_from_manager") - self.mock_wait_for = mockpatch.Patch( + self.mock_wait_for = fixtures.MockPatch( self.benchmark_utils + ".wait_for") - self.mock_wait_for_delete = mockpatch.Patch( + self.mock_wait_for_delete = fixtures.MockPatch( self.benchmark_utils + ".wait_for_delete") - self.mock_wait_for_status = mockpatch.Patch( + self.mock_wait_for_status = fixtures.MockPatch( self.benchmark_utils + ".wait_for_status") self.useFixture(self.mock_resource_is) self.useFixture(self.mock_get_from_manager) @@ -135,7 +135,7 @@ class ScenarioTestCase(TestCase): self.useFixture(self.mock_wait_for_delete) self.useFixture(self.mock_wait_for_status) - self.mock_sleep = mockpatch.Patch("time.sleep") + self.mock_sleep = fixtures.MockPatch("time.sleep") self.useFixture(self.mock_sleep) self._clients = {}