From f92e6d42f0105004f6647b028acc64a202c2b2ca Mon Sep 17 00:00:00 2001 From: "jeremy.zhang" Date: Thu, 21 Sep 2017 12:37:32 +0800 Subject: [PATCH] Remove deprecated skip decorators This patch aims to remove 'skip_unless_config' and 'skip_if_config' decorators, which marked as deprecated and would be removed in Queens. Change-Id: I45a0216b7ab34e962b0f4802df77019b0c613d49 --- ...ated-skip-decorators-f8b42d812d20b537.yaml | 5 + tempest/config.py | 76 --------------- tempest/tests/test_decorators.py | 93 ------------------- 3 files changed, 5 insertions(+), 169 deletions(-) create mode 100644 releasenotes/notes/remove-deprecated-skip-decorators-f8b42d812d20b537.yaml diff --git a/releasenotes/notes/remove-deprecated-skip-decorators-f8b42d812d20b537.yaml b/releasenotes/notes/remove-deprecated-skip-decorators-f8b42d812d20b537.yaml new file mode 100644 index 0000000000..920bc5d322 --- /dev/null +++ b/releasenotes/notes/remove-deprecated-skip-decorators-f8b42d812d20b537.yaml @@ -0,0 +1,5 @@ +--- +upgrade: + - | + Remove two deprecated skip decorators in ``config`` module: + ``skip_unless_config`` and ``skip_if_config``. diff --git a/tempest/config.py b/tempest/config.py index e78a07fd6b..4d0839ac34 100644 --- a/tempest/config.py +++ b/tempest/config.py @@ -15,15 +15,12 @@ from __future__ import print_function -import functools import os import tempfile -import debtcollector.removals from oslo_concurrency import lockutils from oslo_config import cfg from oslo_log import log as logging -import testtools from tempest.lib import exceptions from tempest.lib.services import clients @@ -1284,79 +1281,6 @@ class TempestConfigProxy(object): CONF = TempestConfigProxy() -@debtcollector.removals.remove( - message='use testtools.skipUnless instead', removal_version='Queens') -def skip_unless_config(*args): - """Decorator to raise a skip if a config opt doesn't exist or is False - - :param str group: The first arg, the option group to check - :param str name: The second arg, the option name to check - :param str msg: Optional third arg, the skip msg to use if a skip is raised - :raises testtools.TestCaseskipException: If the specified config option - doesn't exist or it exists and evaluates to False - """ - def decorator(f): - group = args[0] - name = args[1] - - @functools.wraps(f) - def wrapper(self, *func_args, **func_kwargs): - if not hasattr(CONF, group): - msg = "Config group %s doesn't exist" % group - raise testtools.TestCase.skipException(msg) - - conf_group = getattr(CONF, group) - if not hasattr(conf_group, name): - msg = "Config option %s.%s doesn't exist" % (group, - name) - raise testtools.TestCase.skipException(msg) - - value = getattr(conf_group, name) - if not value: - if len(args) == 3: - msg = args[2] - else: - msg = "Config option %s.%s is false" % (group, - name) - raise testtools.TestCase.skipException(msg) - return f(self, *func_args, **func_kwargs) - return wrapper - return decorator - - -@debtcollector.removals.remove( - message='use testtools.skipIf instead', removal_version='Queens') -def skip_if_config(*args): - """Raise a skipException if a config exists and is True - - :param str group: The first arg, the option group to check - :param str name: The second arg, the option name to check - :param str msg: Optional third arg, the skip msg to use if a skip is raised - :raises testtools.TestCase.skipException: If the specified config option - exists and evaluates to True - """ - def decorator(f): - group = args[0] - name = args[1] - - @functools.wraps(f) - def wrapper(self, *func_args, **func_kwargs): - if hasattr(CONF, group): - conf_group = getattr(CONF, group) - if hasattr(conf_group, name): - value = getattr(conf_group, name) - if value: - if len(args) == 3: - msg = args[2] - else: - msg = "Config option %s.%s is false" % (group, - name) - raise testtools.TestCase.skipException(msg) - return f(self, *func_args, **func_kwargs) - return wrapper - return decorator - - def service_client_config(service_client_name=None): """Return a dict with the parameters to init service clients diff --git a/tempest/tests/test_decorators.py b/tempest/tests/test_decorators.py index bf0428081d..6018441169 100644 --- a/tempest/tests/test_decorators.py +++ b/tempest/tests/test_decorators.py @@ -176,96 +176,3 @@ class TestRequiresExtDecorator(BaseDecoratorsTest): self._test_requires_ext_helper, extension='enabled_ext', service='bad_service') - - -class TestConfigDecorators(BaseDecoratorsTest): - def setUp(self): - super(TestConfigDecorators, self).setUp() - cfg.CONF.set_default('nova', True, 'service_available') - cfg.CONF.set_default('glance', False, 'service_available') - - def _assert_skip_message(self, func, skip_msg): - try: - func() - self.fail() - except testtools.TestCase.skipException as skip_exc: - self.assertEqual(skip_exc.args[0], skip_msg) - - def _test_skip_unless_config(self, expected_to_skip=True, *decorator_args): - - class TestFoo(test.BaseTestCase): - @config.skip_unless_config(*decorator_args) - def test_bar(self): - return 0 - - t = TestFoo('test_bar') - if expected_to_skip: - self.assertRaises(testtools.TestCase.skipException, t.test_bar) - if (len(decorator_args) >= 3): - # decorator_args[2]: skip message specified - self._assert_skip_message(t.test_bar, decorator_args[2]) - else: - try: - self.assertEqual(t.test_bar(), 0) - except testtools.TestCase.skipException: - # We caught a skipException but we didn't expect to skip - # this test so raise a hard test failure instead. - raise testtools.TestCase.failureException( - "Not supposed to skip") - - def _test_skip_if_config(self, expected_to_skip=True, - *decorator_args): - - class TestFoo(test.BaseTestCase): - @config.skip_if_config(*decorator_args) - def test_bar(self): - return 0 - - t = TestFoo('test_bar') - if expected_to_skip: - self.assertRaises(testtools.TestCase.skipException, t.test_bar) - if (len(decorator_args) >= 3): - # decorator_args[2]: skip message specified - self._assert_skip_message(t.test_bar, decorator_args[2]) - else: - try: - self.assertEqual(t.test_bar(), 0) - except testtools.TestCase.skipException: - # We caught a skipException but we didn't expect to skip - # this test so raise a hard test failure instead. - raise testtools.TestCase.failureException( - "Not supposed to skip") - - def test_skip_unless_no_group(self): - self._test_skip_unless_config(True, 'fake_group', 'an_option') - - def test_skip_unless_no_option(self): - self._test_skip_unless_config(True, 'service_available', - 'not_an_option') - - def test_skip_unless_false_option(self): - self._test_skip_unless_config(True, 'service_available', 'glance') - - def test_skip_unless_false_option_msg(self): - self._test_skip_unless_config(True, 'service_available', 'glance', - 'skip message') - - def test_skip_unless_true_option(self): - self._test_skip_unless_config(False, - 'service_available', 'nova') - - def test_skip_if_no_group(self): - self._test_skip_if_config(False, 'fake_group', 'an_option') - - def test_skip_if_no_option(self): - self._test_skip_if_config(False, 'service_available', 'not_an_option') - - def test_skip_if_false_option(self): - self._test_skip_if_config(False, 'service_available', 'glance') - - def test_skip_if_true_option(self): - self._test_skip_if_config(True, 'service_available', 'nova') - - def test_skip_if_true_option_msg(self): - self._test_skip_if_config(True, 'service_available', 'nova', - 'skip message')