From 7275483e014a67b0ed8dbe48b5b4dda466a7fa9c Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Fri, 1 Mar 2024 16:54:19 +0100 Subject: [PATCH] Skip tests using heat when heat service is not deployed This patch includes a hack to avoid skipping unit tests that mock the heat client. Change-Id: Id0fd820abc2e8d0c62cdb69206aaf8e0a426f7e0 --- tobiko/openstack/heat/_client.py | 2 ++ tobiko/openstack/keystone/_services.py | 7 ++++++- tobiko/tests/unit/openstack/heat/test_client.py | 7 ------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tobiko/openstack/heat/_client.py b/tobiko/openstack/heat/_client.py index e66361fae..7e0942598 100644 --- a/tobiko/openstack/heat/_client.py +++ b/tobiko/openstack/heat/_client.py @@ -19,6 +19,7 @@ from heatclient.v1 import client as v1_client import tobiko from tobiko.openstack import _client +from tobiko.openstack import keystone HeatClient = typing.Union[v1_client.Client] @@ -46,6 +47,7 @@ HeatClientType = typing.Union[None, HeatClientFixture] +@keystone.skip_if_missing_service(name='heat') def heat_client(obj: HeatClientType = None) -> HeatClient: if obj is None: return default_heat_client() diff --git a/tobiko/openstack/keystone/_services.py b/tobiko/openstack/keystone/_services.py index e9d0d8e46..6dbd8a6c8 100644 --- a/tobiko/openstack/keystone/_services.py +++ b/tobiko/openstack/keystone/_services.py @@ -13,6 +13,8 @@ # under the License. from __future__ import absolute_import +import inspect + import tobiko from tobiko.openstack.keystone import _client @@ -38,7 +40,10 @@ def has_service(**attributes): def is_service_missing(**params): - return not has_service(**params) + # return False if it is called from a unit test + test_module_name = inspect.getmodule(tobiko.get_test_case()).__name__ + return (not test_module_name.startswith('tobiko.tests.unit.') and + not has_service(**params)) def skip_if_missing_service(**params): diff --git a/tobiko/tests/unit/openstack/heat/test_client.py b/tobiko/tests/unit/openstack/heat/test_client.py index ff9e81806..6d7fa5257 100644 --- a/tobiko/tests/unit/openstack/heat/test_client.py +++ b/tobiko/tests/unit/openstack/heat/test_client.py @@ -19,18 +19,11 @@ import mock from tobiko.openstack import keystone from tobiko.openstack import heat from tobiko.tests.unit import openstack -from tobiko.tests.unit.openstack import test_client MockClient = mock.create_autospec(heatclient.Client) -class HeatClientFixtureTest(test_client.OpenstackClientFixtureTest): - - def create_client(self, session=None): - return heat.HeatClientFixture(session=session) - - class GetHeatClientTest(openstack.OpenstackTest): def test_get_heat_client(self, session=None, shared=True):