Replace use of testtools.testcase.TestSkipped

This has been deprecated for removal [1]. Use the stdlib variant
instead.

[1] https://github.com/testing-cabal/testtools/commit/59b890db3c

Change-Id: I7701872d2de44bb7c8296501015c24d0741adc93
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2024-06-24 10:43:09 +01:00
parent dd61a91864
commit 53d547fcb8
4 changed files with 13 additions and 15 deletions

View File

@ -180,7 +180,7 @@ including:
in code if a fix isn't ready yet.
The :func:`keystone.tests.unit.utils.wip` decorator can be used to mark a test
as WIP. A WIP test will always be run. If the test fails then a TestSkipped
as WIP. A WIP test will always be run. If the test fails then a SkipTest
exception is raised because we expect the test to fail. We do not pass
the test in this case so that it doesn't count toward the number of
successfully run tests. If the test passes an AssertionError exception is

View File

@ -19,13 +19,13 @@ import datetime
import functools
import hashlib
import json
import secrets
import ldap
import os
import secrets
import shutil
import socket
import sys
import unittest
import uuid
from cryptography.hazmat.primitives.asymmetric import rsa
@ -43,7 +43,6 @@ from oslo_log import fixture as log_fixture
from oslo_log import log
from oslo_utils import timeutils
import testtools
from testtools import testcase
import keystone.api
from keystone.common import context
@ -154,12 +153,12 @@ def skip_if_cache_disabled(*sections):
@functools.wraps(f)
def inner(*args, **kwargs):
if not CONF.cache.enabled:
raise testcase.TestSkipped('Cache globally disabled.')
raise unittest.SkipTest('Cache globally disabled.')
for s in sections:
conf_sec = getattr(CONF, s, None)
if conf_sec is not None:
if not getattr(conf_sec, 'caching', True):
raise testcase.TestSkipped('%s caching disabled.' % s)
raise unittest.SkipTest('%s caching disabled.' % s)
return f(*args, **kwargs)
return inner
return wrapper
@ -174,8 +173,7 @@ def skip_if_cache_is_enabled(*sections):
conf_sec = getattr(CONF, s, None)
if conf_sec is not None:
if getattr(conf_sec, 'caching', True):
raise testcase.TestSkipped('%s caching enabled.' %
s)
raise unittest.SkipTest('%s caching enabled.' % s)
return f(*args, **kwargs)
return inner
return wrapper
@ -187,7 +185,7 @@ def skip_if_no_multiple_domains_support(f):
def wrapper(*args, **kwargs):
test_obj = args[0]
if not test_obj.identity_api.multiple_domains_supported:
raise testcase.TestSkipped('No multiple domains support')
raise unittest.SkipTest('No multiple domains support')
return f(*args, **kwargs)
return wrapper

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import unittest
from testtools import matchers
from testtools import testcase
@ -24,7 +26,7 @@ class TestWipDecorator(testcase.TestCase):
def test():
raise Exception('i expected a failure - this is a WIP')
e = self.assertRaises(testcase.TestSkipped, test)
e = self.assertRaises(unittest.SkipTest, test)
self.assertThat(str(e), matchers.Contains('#000000'))
def test_raises_AssertionError_when_test_passes(self):

View File

@ -15,11 +15,9 @@
import functools
import os
import time
import unittest
import uuid
from testtools import testcase
TZ = None
@ -54,7 +52,7 @@ def wip(message, expected_exception=Exception, bug=None):
Based on code by Nat Pryce:
https://gist.github.com/npryce/997195#file-wip-py
The test will always be run. If the test fails then a TestSkipped
The test will always be run. If the test fails then a SkipTest
exception is raised. If the test passes an AssertionError exception
is raised so that the developer knows they made the test pass. This
is a reminder to remove the decorator.
@ -97,7 +95,7 @@ def wip(message, expected_exception=Exception, bug=None):
'exception': __e.__class__.__name__})
# NOTE(notmorgan): We got the expected exception we can safely
# skip this test.
raise testcase.TestSkipped(
raise unittest.SkipTest(
'Work In Progress Test Failed as '
'expected%(bugstr)s: %(message)s' %
{'message': message, 'bugstr': bugstr})