From 5b56140650969505f34a02f51f3b480d4609b7af Mon Sep 17 00:00:00 2001 From: dkorn Date: Thu, 1 Jan 2015 16:48:07 +0200 Subject: [PATCH] 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 --- .../integration_tests/tests/decorators.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/openstack_dashboard/test/integration_tests/tests/decorators.py b/openstack_dashboard/test/integration_tests/tests/decorators.py index 07f8289fa5..b10ede4f01 100644 --- a/openstack_dashboard/test/integration_tests/tests/decorators.py +++ b/openstack_dashboard/test/integration_tests/tests/decorators.py @@ -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