Skip test cases by setUp method instead of setUpClass method.

setUpClass method is exectuted only once. It looks like
skipping test cases at such level it could skip only the
first test case method instead of all ones. Actually
tipically test cases are skept using self.skip() method,
therefore the behavior of skipping at class level
could be probably unsupported by test runners.

Change-Id: I803b2712849201bc013e8645b2b81781ad4193f9
This commit is contained in:
Federico Ressi
2019-04-23 14:11:02 +02:00
parent a0c598cd3d
commit 5c911bc534
2 changed files with 41 additions and 10 deletions

View File

@@ -43,7 +43,7 @@ def skip_until(reason, predicate, *args, **kwargs):
def skip_if_match(reason, match, predicate, *args, **kwargs):
def decorator(obj):
method, is_class_method = _get_decorated_method(obj)
method = _get_decorated_method(obj)
@functools.wraps(method)
def wrapped_method(*_args, **_kwargs):
@@ -55,9 +55,6 @@ def skip_if_match(reason, match, predicate, *args, **kwargs):
if obj is method:
return wrapped_method
else:
if is_class_method:
wrapped_method = classmethod(wrapped_method)
setattr(obj, method.__name__, wrapped_method)
return obj
@@ -67,13 +64,13 @@ def skip_if_match(reason, match, predicate, *args, **kwargs):
def _get_decorated_method(obj):
if inspect.isclass(obj):
if issubclass(obj, (unittest.TestCase, testtools.TestCase)):
return obj.setUpClass, True
return obj.setUp
elif _fixture.is_fixture(obj):
return obj.setUp, False
return obj.setUp
else:
raise TypeError("Cannot decorate class {!r}".format(obj))
else:
if callable(obj):
return obj, False
return obj
else:
raise TypeError("Cannot decorate object {!r}".format(obj))