Merge "Refactor skip_because decorator"

This commit is contained in:
Zuul 2021-02-11 02:07:55 +00:00 committed by Gerrit Code Review
commit 76a9af2e26

View File

@ -72,19 +72,13 @@ def skip_because(*args, **kwargs):
def decorator(f): def decorator(f):
@functools.wraps(f) @functools.wraps(f)
def wrapper(*func_args, **func_kwargs): def wrapper(*func_args, **func_kwargs):
skip = False condition = kwargs.get('condition', True)
msg = '' bug = kwargs.get('bug', None)
if "condition" in kwargs: if bug and condition:
if kwargs["condition"] is True:
skip = True
else:
skip = True
if "bug" in kwargs and skip is True:
bug = kwargs['bug']
bug_type = kwargs.get('bug_type', 'launchpad') bug_type = kwargs.get('bug_type', 'launchpad')
bug_url = _get_bug_url(bug, bug_type) bug_url = _get_bug_url(bug, bug_type)
msg = "Skipped until bug: %s is resolved." % bug_url raise testtools.TestCase.skipException(
raise testtools.TestCase.skipException(msg) "Skipped until bug: %s is resolved." % bug_url)
return f(*func_args, **func_kwargs) return f(*func_args, **func_kwargs)
return wrapper return wrapper
return decorator return decorator