Merge "Add new functionality to @wip"

This commit is contained in:
Jenkins 2016-05-23 02:57:34 +00:00 committed by Gerrit Code Review
commit 5bc7b34f69

View File

@ -49,7 +49,7 @@ def new_uuid():
return uuid.uuid4().hex return uuid.uuid4().hex
def wip(message): def wip(message, expected_exception=Exception, bug=None):
"""Mark a test as work in progress. """Mark a test as work in progress.
Based on code by Nat Pryce: Based on code by Nat Pryce:
@ -62,23 +62,50 @@ def wip(message):
:param message: a string message to help clarify why the test is :param message: a string message to help clarify why the test is
marked as a work in progress marked as a work in progress
:param expected_exception: an exception class that will be checked for
when @wip verifies an exception is raised. The
test will fail if a different exception is
raised. Default is "any" exception is valid
:param bug: (optional) a string for tracking the bug and what bug should
cause the @wip decorator to be removed from the testcase
usage: Usage:
>>> @wip('waiting on bug #000000') >>> @wip('Expected Error', expected_exception=Exception, bug="#000000")
>>> def test(): >>> def test():
>>> pass >>> pass
""" """
if bug:
bugstr = " (BugID " + bug + ")"
else:
bugstr = ""
def _wip(f): def _wip(f):
@six.wraps(f) @six.wraps(f)
def run_test(*args, **kwargs): def run_test(*args, **kwargs):
__e = None
try: try:
f(*args, **kwargs) f(*args, **kwargs)
except Exception: except Exception as __e:
raise testcase.TestSkipped('work in progress test failed: ' + if (expected_exception != Exception and
message) not isinstance(__e, expected_exception)):
raise AssertionError(
'Work In Progress Test Failed%(bugstr)s with '
'unexpected exception. Expected "%(expected)s" '
'got "%(exception)s": %(message)s ' %
{'message': message, 'bugstr': bugstr,
'expected': expected_exception.__class__.__name__,
'exception': __e.__class__.__name__})
# NOTE(notmorgan): We got the expected exception we can safely
# skip this test.
raise testcase.TestSkipped(
'Work In Progress Test Failed as '
'expected%(bugstr)s: %(message)s' %
{'message': message, 'bugstr': bugstr})
raise AssertionError('work in progress test passed: ' + message) raise AssertionError('Work In Progress Test Passed%(bugstr)s: '
'%(message)s' % {'message': message,
'bugstr': bugstr})
return run_test return run_test