Decorator for skipping tests hitting known bugs

Adding skip_because decorator that can be used for decorating test
classes as well as test methods.
Decorator expects to recieve the bug numbers causing the test to skip.

Partially implements blueprint: selenium-integration-testing
Closes-Bug: #1406950

Change-Id: Ie5eec615f09b6b2b20a73e372db2371ab1bf2819
This commit is contained in:
dkorn 2015-01-01 16:48:07 +02:00
parent d9d8d861b1
commit 5b56140650
1 changed files with 36 additions and 0 deletions

View File

@ -9,6 +9,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import collections
import functools
import inspect
@ -96,3 +98,37 @@ def services_required(*req_services):
break
return obj
return actual_decoration
def skip_because(**kwargs):
"""Decorator for skipping tests hitting known bugs
Usage:
from openstack_dashboard.test.integration_tests.tests import decorators
class TestDashboardHelp(helpers.TestCase):
@decorators.skip_because(bugs=["1234567"])
def test_dashboard_help_redirection(self):
.
.
.
"""
def actual_decoration(obj):
if inspect.isclass(obj):
if not _is_test_cls(obj):
raise ValueError(NOT_TEST_OBJECT_ERROR_MSG)
skip_method = _mark_class_skipped
else:
if not _is_test_method_name(obj.func_name):
raise ValueError(NOT_TEST_OBJECT_ERROR_MSG)
skip_method = _mark_method_skipped
bugs = kwargs.get("bugs")
if bugs and isinstance(bugs, collections.Iterable):
for bug in bugs:
if not bug.isdigit():
raise ValueError("bug must be a valid bug number")
obj = skip_method(obj, "Skipped until Bugs: %s are resolved."
", ".join([bug for bug in bugs]))
return obj
return actual_decoration