aboutsummaryrefslogtreecommitdiffstats
path: root/xtesting/core/testcase.py
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-07-15 09:49:57 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2018-08-07 05:43:45 +0200
commit9bc7599c56b2940aa712efdbac20c489659571f9 (patch)
tree83dc869ee4563c1efa793dfafb5bb84aac147b68 /xtesting/core/testcase.py
parent8a47fa355754b30f6b6fa9e9f55c7dc4149ac9c9 (diff)
Allow dynamically skipping testcases
Change-Id: I7cf47f0625bdb8345fef43b24c51bd84ef4486ea Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com> (cherry picked from commit 3aee76caccf9701e2c90652a920c1bca66903bb8)
Diffstat (limited to 'xtesting/core/testcase.py')
-rw-r--r--xtesting/core/testcase.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/xtesting/core/testcase.py b/xtesting/core/testcase.py
index 4effa932..61a2e8c8 100644
--- a/xtesting/core/testcase.py
+++ b/xtesting/core/testcase.py
@@ -16,17 +16,15 @@ import os
import re
import requests
-from xtesting.utils import decorators
-from xtesting.utils import env
-
-
import prettytable
+from xtesting.utils import decorators
+from xtesting.utils import env
__author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
-class TestCase(object):
+class TestCase(object): # pylint: disable=too-many-instance-attributes
"""Base model for single test case."""
EX_OK = os.EX_OK
@@ -41,6 +39,9 @@ class TestCase(object):
EX_TESTCASE_FAILED = os.EX_SOFTWARE - 2
"""results are false"""
+ EX_TESTCASE_SKIPPED = os.EX_SOFTWARE - 3
+ """requirements are unmet"""
+
_job_name_rule = "(dai|week)ly-(.+?)-[0-9]*"
_headers = {'Content-Type': 'application/json'}
__logger = logging.getLogger(__name__)
@@ -53,13 +54,17 @@ class TestCase(object):
self.result = 0
self.start_time = 0
self.stop_time = 0
+ self.is_skipped = False
def __str__(self):
try:
assert self.project_name
assert self.case_name
- result = 'PASS' if(self.is_successful(
- ) == TestCase.EX_OK) else 'FAIL'
+ if self.is_skipped:
+ result = 'SKIP'
+ else:
+ result = 'PASS' if(self.is_successful(
+ ) == TestCase.EX_OK) else 'FAIL'
msg = prettytable.PrettyTable(
header_style='upper', padding_width=5,
field_names=['test case', 'project', 'duration',
@@ -79,6 +84,8 @@ class TestCase(object):
"XX:XX" otherwise.
"""
try:
+ if self.is_skipped:
+ return "00:00"
assert self.start_time
assert self.stop_time
if self.stop_time < self.start_time:
@@ -99,9 +106,12 @@ class TestCase(object):
Returns:
TestCase.EX_OK if result is 'PASS'.
+ TestCase.EX_TESTCASE_SKIPPED if test case is skipped.
TestCase.EX_TESTCASE_FAILED otherwise.
"""
try:
+ if self.is_skipped:
+ return TestCase.EX_TESTCASE_SKIPPED
assert self.criteria
assert self.result is not None
if (not isinstance(self.result, str) and
@@ -121,6 +131,13 @@ class TestCase(object):
self.__logger.error("Please run test before checking the results")
return TestCase.EX_TESTCASE_FAILED
+ def check_requirements(self): # pylint: disable=no-self-use
+ """Check the requirements of the test case.
+
+ It can be overriden on purpose.
+ """
+ self.is_skipped = False
+
def run(self, **kwargs):
"""Run the test case.
@@ -177,6 +194,8 @@ class TestCase(object):
TestCase.EX_PUSH_TO_DB_ERROR otherwise.
"""
try:
+ if self.is_skipped:
+ return TestCase.EX_PUSH_TO_DB_ERROR
assert self.project_name
assert self.case_name
assert self.start_time