Rehome unstable_test decorator

The unstable_test decorator is used in both neutron and
neutron-tempest-plugin trees, so lets move to neutron-lib.

Change-Id: Ieba747097b6e2afbfbe2c71d395217574d679c9a
This commit is contained in:
Brian Haley 2018-04-10 13:53:20 -04:00
parent eafc3f8b16
commit 31f65b8f93
3 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,26 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from neutron_lib.tests import _base as base
from neutron_lib.utils import test
class TestUnstableTestDecorator(base.BaseTestCase):
@test.unstable_test("some bug")
def test_unstable_pass(self):
self.assertIsNone(None)
@test.unstable_test("some other bug")
def test_unstable_fail(self):
self.assertIsNotNone(None)

34
neutron_lib/utils/test.py Normal file
View File

@ -0,0 +1,34 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test functions."""
import functools
def unstable_test(reason):
"""Decorator used to mark test as unstable, on failure test will be skipped
:param reason: String used in explanation, for example, 'bug 123456'.
"""
def decor(f):
@functools.wraps(f)
def inner(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except Exception as e:
msg = ("%s was marked as unstable because of %s, "
"failure was: %s") % (self.id(), reason, e)
raise self.skipTest(msg)
return inner
return decor

View File

@ -0,0 +1,4 @@
---
features:
- The ``unstable_test`` decorator from ``neutron.tests.base`` is now
available in neutron-lib in ``neutron_lib.utils.test``.