From c52e404262e9a81afcdad1abed631699a14ec953 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Fri, 7 Jul 2023 14:32:05 -0700 Subject: [PATCH] tests: Skip keystoneauth tests if not available Change-Id: I80af28b49415c5bea6399683922b6649f04ed011 --- test/unit/test_authv1.py | 17 +++++++++++++---- test/unit/test_swiftclient.py | 5 ++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/test/unit/test_authv1.py b/test/unit/test_authv1.py index b4de7e0f..c22cc39c 100644 --- a/test/unit/test_authv1.py +++ b/test/unit/test_authv1.py @@ -16,10 +16,13 @@ import datetime import json import unittest from unittest import mock -from keystoneauth1 import plugin -from keystoneauth1 import loading -from keystoneauth1 import exceptions -from swiftclient import authv1 +try: + from keystoneauth1 import plugin + from keystoneauth1 import loading + from keystoneauth1 import exceptions + from swiftclient import authv1 +except ImportError: + plugin = loading = exceptions = authv1 = None class TestDataNoAccount: @@ -44,6 +47,10 @@ class TestDataWithAccount: class TestPluginLoading(TestDataNoAccount, unittest.TestCase): + def setUp(self): + if authv1 is None: + raise unittest.SkipTest('keystoneauth1 is not available') + def test_can_load(self): loader = loading.get_plugin_loader('v1password') self.assertIsInstance(loader, authv1.PasswordLoader) @@ -120,6 +127,8 @@ class TestPluginLoadingWithAccount(TestDataWithAccount, TestPluginLoading): class TestPlugin(TestDataNoAccount, unittest.TestCase): def setUp(self): + if authv1 is None: + raise unittest.SkipTest('keystoneauth1 is not available') self.mock_session = mock.MagicMock() self.mock_response = self.mock_session.get.return_value self.mock_response.status_code = 200 diff --git a/test/unit/test_swiftclient.py b/test/unit/test_swiftclient.py index 42d470cd..be4f4a5e 100644 --- a/test/unit/test_swiftclient.py +++ b/test/unit/test_swiftclient.py @@ -579,7 +579,10 @@ class TestGetAuth(MockHttpTest): self.assertTrue(token) def test_auth_v3applicationcredential(self): - from keystoneauth1 import exceptions as ksauthexceptions + try: + from keystoneauth1 import exceptions as ksauthexceptions + except ImportError: + raise unittest.SkipTest('keystoneauth1 is not available') os_options = { "auth_type": "v3applicationcredential",