Remove deprecated skip_unless_attr decorator
This patch aims to remove 'skip_unless_attr' decorator, which marked as deprecated and would be removed in Queens. Change-Id: I33fb4466df2747fdbbf023373e53079a99a4d2c2
This commit is contained in:
parent
e12d98aacf
commit
0648215f58
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
upgrade:
|
||||||
|
- |
|
||||||
|
Remove the deprecated decorator ``skip_unless_attr`` in lib/decorators.py.
|
@ -15,7 +15,6 @@
|
|||||||
import functools
|
import functools
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import debtcollector.removals
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
import six
|
||||||
import testtools
|
import testtools
|
||||||
@ -87,25 +86,6 @@ def idempotent_id(id):
|
|||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
@debtcollector.removals.remove(removal_version='Queen')
|
|
||||||
class skip_unless_attr(object):
|
|
||||||
"""Decorator to skip tests if a specified attr does not exists or False"""
|
|
||||||
def __init__(self, attr, msg=None):
|
|
||||||
self.attr = attr
|
|
||||||
self.message = msg or ("Test case attribute %s not found "
|
|
||||||
"or False") % attr
|
|
||||||
|
|
||||||
def __call__(self, func):
|
|
||||||
@functools.wraps(func)
|
|
||||||
def _skipper(*args, **kw):
|
|
||||||
"""Wrapped skipper function."""
|
|
||||||
testobj = args[0]
|
|
||||||
if not getattr(testobj, self.attr, False):
|
|
||||||
raise testtools.TestCase.skipException(self.message)
|
|
||||||
func(*args, **kw)
|
|
||||||
return _skipper
|
|
||||||
|
|
||||||
|
|
||||||
def attr(**kwargs):
|
def attr(**kwargs):
|
||||||
"""A decorator which applies the testtools attr decorator
|
"""A decorator which applies the testtools attr decorator
|
||||||
|
|
||||||
|
@ -125,35 +125,6 @@ class TestIdempotentIdDecorator(base.TestCase):
|
|||||||
self.assertRaises(ValueError, self._test_helper, _id)
|
self.assertRaises(ValueError, self._test_helper, _id)
|
||||||
|
|
||||||
|
|
||||||
class TestSkipUnlessAttrDecorator(base.TestCase):
|
|
||||||
def _test_skip_unless_attr(self, attr, expected_to_skip=True):
|
|
||||||
class TestFoo(test.BaseTestCase):
|
|
||||||
expected_attr = not expected_to_skip
|
|
||||||
|
|
||||||
@decorators.skip_unless_attr(attr)
|
|
||||||
def test_foo(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
t = TestFoo('test_foo')
|
|
||||||
if expected_to_skip:
|
|
||||||
self.assertRaises(testtools.TestCase.skipException,
|
|
||||||
t.test_foo)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
t.test_foo()
|
|
||||||
except Exception:
|
|
||||||
raise testtools.TestCase.failureException()
|
|
||||||
|
|
||||||
def test_skip_attr_does_not_exist(self):
|
|
||||||
self._test_skip_unless_attr('unexpected_attr')
|
|
||||||
|
|
||||||
def test_skip_attr_false(self):
|
|
||||||
self._test_skip_unless_attr('expected_attr')
|
|
||||||
|
|
||||||
def test_no_skip_for_attr_exist_and_true(self):
|
|
||||||
self._test_skip_unless_attr('expected_attr', expected_to_skip=False)
|
|
||||||
|
|
||||||
|
|
||||||
class TestRelatedBugDecorator(base.TestCase):
|
class TestRelatedBugDecorator(base.TestCase):
|
||||||
def test_relatedbug_when_no_exception(self):
|
def test_relatedbug_when_no_exception(self):
|
||||||
f = mock.Mock()
|
f = mock.Mock()
|
||||||
|
Loading…
Reference in New Issue
Block a user