|
|
|
@ -13,7 +13,10 @@
|
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
|
|
import abc
|
|
|
|
|
|
|
|
|
|
import mock
|
|
|
|
|
import six
|
|
|
|
|
import testtools
|
|
|
|
|
|
|
|
|
|
from tempest.lib import base as test
|
|
|
|
@ -66,9 +69,36 @@ class TestAttrDecorator(base.TestCase):
|
|
|
|
|
condition=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestSkipBecauseDecorator(base.TestCase):
|
|
|
|
|
def _test_skip_because_helper(self, expected_to_skip=True,
|
|
|
|
|
**decorator_args):
|
|
|
|
|
@six.add_metaclass(abc.ABCMeta)
|
|
|
|
|
class BaseSkipDecoratorTests(object):
|
|
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
|
def _test_skip_helper(self, raise_exception=True, expected_to_skip=True,
|
|
|
|
|
**decorator_args):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def test_skip_launchpad_bug(self):
|
|
|
|
|
self._test_skip_helper(bug='12345')
|
|
|
|
|
|
|
|
|
|
def test_skip_storyboard_bug(self):
|
|
|
|
|
self._test_skip_helper(bug='1992', bug_type='storyboard')
|
|
|
|
|
|
|
|
|
|
def test_skip_bug_without_bug_never_skips(self):
|
|
|
|
|
"""Never skip without a bug parameter."""
|
|
|
|
|
self._test_skip_helper(
|
|
|
|
|
raise_exception=False, expected_to_skip=False, condition=True)
|
|
|
|
|
self._test_skip_helper(
|
|
|
|
|
raise_exception=False, expected_to_skip=False)
|
|
|
|
|
|
|
|
|
|
def test_skip_invalid_bug_number(self):
|
|
|
|
|
"""Raise InvalidParam if with an invalid bug number"""
|
|
|
|
|
self.assertRaises(lib_exc.InvalidParam, self._test_skip_helper,
|
|
|
|
|
bug='critical_bug')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestSkipBecauseDecorator(base.TestCase, BaseSkipDecoratorTests):
|
|
|
|
|
def _test_skip_helper(self, raise_exception=True, expected_to_skip=True,
|
|
|
|
|
**decorator_args):
|
|
|
|
|
class TestFoo(test.BaseTestCase):
|
|
|
|
|
_interface = 'json'
|
|
|
|
|
|
|
|
|
@ -90,38 +120,56 @@ class TestSkipBecauseDecorator(base.TestCase):
|
|
|
|
|
# assert that test_bar returned 0
|
|
|
|
|
self.assertEqual(TestFoo('test_bar').test_bar(), 0)
|
|
|
|
|
|
|
|
|
|
def test_skip_because_launchpad_bug(self):
|
|
|
|
|
self._test_skip_because_helper(bug='12345')
|
|
|
|
|
|
|
|
|
|
def test_skip_because_launchpad_bug_and_condition_true(self):
|
|
|
|
|
self._test_skip_because_helper(bug='12348', condition=True)
|
|
|
|
|
self._test_skip_helper(bug='12348', condition=True)
|
|
|
|
|
|
|
|
|
|
def test_skip_because_launchpad_bug_and_condition_false(self):
|
|
|
|
|
self._test_skip_because_helper(expected_to_skip=False,
|
|
|
|
|
bug='12349', condition=False)
|
|
|
|
|
self._test_skip_helper(expected_to_skip=False,
|
|
|
|
|
bug='12349', condition=False)
|
|
|
|
|
|
|
|
|
|
def test_skip_because_storyboard_bug(self):
|
|
|
|
|
self._test_skip_because_helper(bug='1992', bug_type='storyboard')
|
|
|
|
|
def test_skip_because_storyboard_bug_and_condition_false(self):
|
|
|
|
|
self._test_skip_helper(expected_to_skip=False,
|
|
|
|
|
bug='1992', bug_type='storyboard',
|
|
|
|
|
condition=False)
|
|
|
|
|
|
|
|
|
|
def test_skip_because_storyboard_bug_and_condition_true(self):
|
|
|
|
|
self._test_skip_because_helper(bug='1992', bug_type='storyboard',
|
|
|
|
|
condition=True)
|
|
|
|
|
self._test_skip_helper(bug='1992', bug_type='storyboard',
|
|
|
|
|
condition=True)
|
|
|
|
|
|
|
|
|
|
def test_skip_because_storyboard_bug_and_condition_false(self):
|
|
|
|
|
self._test_skip_because_helper(expected_to_skip=False,
|
|
|
|
|
bug='1992', bug_type='storyboard',
|
|
|
|
|
condition=False)
|
|
|
|
|
|
|
|
|
|
def test_skip_because_bug_without_bug_never_skips(self):
|
|
|
|
|
"""Never skip without a bug parameter."""
|
|
|
|
|
self._test_skip_because_helper(expected_to_skip=False,
|
|
|
|
|
condition=True)
|
|
|
|
|
self._test_skip_because_helper(expected_to_skip=False)
|
|
|
|
|
class TestUnstableTestDecorator(base.TestCase, BaseSkipDecoratorTests):
|
|
|
|
|
|
|
|
|
|
def test_skip_because_invalid_bug_number(self):
|
|
|
|
|
"""Raise InvalidParam if with an invalid bug number"""
|
|
|
|
|
self.assertRaises(lib_exc.InvalidParam, self._test_skip_because_helper,
|
|
|
|
|
bug='critical_bug')
|
|
|
|
|
def _test_skip_helper(self, raise_exception=True, expected_to_skip=True,
|
|
|
|
|
**decorator_args):
|
|
|
|
|
fail_test_reason = "test_bar failed"
|
|
|
|
|
|
|
|
|
|
class TestFoo(test.BaseTestCase):
|
|
|
|
|
|
|
|
|
|
@decorators.unstable_test(**decorator_args)
|
|
|
|
|
def test_bar(self):
|
|
|
|
|
if raise_exception:
|
|
|
|
|
raise Exception(fail_test_reason)
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
t = TestFoo('test_bar')
|
|
|
|
|
if expected_to_skip:
|
|
|
|
|
e = self.assertRaises(testtools.TestCase.skipException, t.test_bar)
|
|
|
|
|
bug = decorator_args['bug']
|
|
|
|
|
bug_type = decorator_args.get('bug_type', 'launchpad')
|
|
|
|
|
self.assertRegex(
|
|
|
|
|
str(e),
|
|
|
|
|
r'Marked as unstable and skipped because of bug\: %s.*, '
|
|
|
|
|
'failure was: %s' % (decorators._get_bug_url(bug, bug_type),
|
|
|
|
|
fail_test_reason)
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
# assert that test_bar returned 0
|
|
|
|
|
self.assertEqual(TestFoo('test_bar').test_bar(), 0)
|
|
|
|
|
|
|
|
|
|
def test_skip_bug_given_exception_not_raised(self):
|
|
|
|
|
self._test_skip_helper(raise_exception=False, expected_to_skip=False,
|
|
|
|
|
bug='1234')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestIdempotentIdDecorator(base.TestCase):
|
|
|
|
|