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:
parent
a0c598cd3d
commit
5c911bc534
@ -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))
|
||||
|
@ -45,17 +45,19 @@ class PositiveSkipMethodTest(unit.TobikoUnitTest):
|
||||
self.fail('Not skipped')
|
||||
|
||||
|
||||
class NegativeSkipMethodTest(unit.TobikoUnitTest):
|
||||
|
||||
class NegativeSkipBase(unit.TobikoUnitTest):
|
||||
test_method_called = False
|
||||
|
||||
def setUp(self):
|
||||
super(NegativeSkipMethodTest, self).setUp()
|
||||
super(NegativeSkipBase, self).setUp()
|
||||
self.addCleanup(self.assert_test_method_called)
|
||||
|
||||
def assert_test_method_called(self):
|
||||
self.assertTrue(self.test_method_called)
|
||||
|
||||
|
||||
class NegativeSkipMethodTest(NegativeSkipBase):
|
||||
|
||||
@tobiko.skip_if('condition value was false',
|
||||
condition, False)
|
||||
def test_skip_if_condition_called_with_args(self):
|
||||
@ -209,3 +211,35 @@ class PositiveSkipUntilConditionCalledWithKwargsTest(unit.TobikoUnitTest):
|
||||
|
||||
def test_fail(self):
|
||||
self.fail('Not skipped')
|
||||
|
||||
|
||||
@tobiko.skip_if('condition value was true',
|
||||
condition, False)
|
||||
class NegativeSkipIfConditionCalledWithArgsTest(NegativeSkipBase):
|
||||
|
||||
def test_fail(self):
|
||||
self.test_method_called = True
|
||||
|
||||
|
||||
@tobiko.skip_if('condition value was true',
|
||||
condition, value=False)
|
||||
class NegativeSkipIfConditionCalledWithKwargsTest(NegativeSkipBase):
|
||||
|
||||
def test_fail(self):
|
||||
self.test_method_called = True
|
||||
|
||||
|
||||
@tobiko.skip_until('condition value was false',
|
||||
condition, True)
|
||||
class NegativeSkipUntilConditionCalledWithArgsTest(NegativeSkipBase):
|
||||
|
||||
def test_fail(self):
|
||||
self.test_method_called = True
|
||||
|
||||
|
||||
@tobiko.skip_until('condition value was false',
|
||||
condition, value=True)
|
||||
class NegativeSkipUntilConditionCalledWithKwargsTest(NegativeSkipBase):
|
||||
|
||||
def test_fail(self):
|
||||
self.test_method_called = True
|
||||
|
Loading…
x
Reference in New Issue
Block a user