Fix skip_because decorator
If we use skip_because decorator, the below error occurs. _StringException: ImportError: Failed to import test module:... And, all tests of the class having the skip_because decorator are not tested. This commit fixes it. Change-Id: I98e51d3bfd8b13dc3ef462eb92b170295f5f142e Closes-Bug: #1236220
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
|
import functools
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -110,11 +111,14 @@ def skip_because(*args, **kwargs):
|
|||||||
@param condition: optional condition to be True for the skip to have place
|
@param condition: optional condition to be True for the skip to have place
|
||||||
"""
|
"""
|
||||||
def decorator(f):
|
def decorator(f):
|
||||||
if "bug" in kwargs:
|
@functools.wraps(f)
|
||||||
if "condition" not in kwargs or kwargs["condition"] is True:
|
def wrapper(*func_args, **func_kwargs):
|
||||||
msg = "Skipped until Bug: %s is resolved." % kwargs["bug"]
|
if "bug" in kwargs:
|
||||||
raise testtools.TestCase.skipException(msg)
|
if "condition" not in kwargs or kwargs["condition"] is True:
|
||||||
return f
|
msg = "Skipped until Bug: %s is resolved." % kwargs["bug"]
|
||||||
|
raise testtools.TestCase.skipException(msg)
|
||||||
|
return f(*func_args, **func_kwargs)
|
||||||
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user