aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-08-10 13:04:11 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2018-08-12 12:08:52 +0200
commita9491ef0948f8fe3eb3772b6b6ae44d86bde7e9b (patch)
tree9dfc1985294fed2e579dc662da9d589baa0be9b8
parentb7f4eaa213b65a266f527d9def7679eac7e0353b (diff)
Skip the selected testcase too0.56
It completes "Allow calling a skip test" [1] [1] https://gerrit.opnfv.org/gerrit/60655 Change-Id: I02499aed56e6b23563165ea1f17b476e12408823 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--tox.ini1
-rw-r--r--xtesting/ci/run_tests.py2
-rw-r--r--xtesting/ci/tier_builder.py5
-rw-r--r--xtesting/ci/tier_handler.py6
-rw-r--r--xtesting/tests/unit/ci/test_run_tests.py41
-rw-r--r--xtesting/tests/unit/ci/test_tier_handler.py2
6 files changed, 51 insertions, 6 deletions
diff --git a/tox.ini b/tox.ini
index 8041008f..6c6de708 100644
--- a/tox.ini
+++ b/tox.ini
@@ -57,7 +57,6 @@ dirs =
xtesting/tests/unit/energy
xtesting/tests/unit/utils/test_decorators.py
commands = nosetests --with-coverage --cover-tests \
- --cover-package xtesting.ci.tier_handler \
--cover-package xtesting.core \
--cover-package xtesting.energy \
--cover-package xtesting.tests.unit \
diff --git a/xtesting/ci/run_tests.py b/xtesting/ci/run_tests.py
index 61482d98..59ed5617 100644
--- a/xtesting/ci/run_tests.py
+++ b/xtesting/ci/run_tests.py
@@ -138,7 +138,7 @@ class Runner(object):
def run_test(self, test):
"""Run one test case"""
- if not test.is_enabled():
+ if not test.is_enabled() or test.is_skipped():
msg = prettytable.PrettyTable(
header_style='upper', padding_width=5,
field_names=['test case', 'project', 'duration',
diff --git a/xtesting/ci/tier_builder.py b/xtesting/ci/tier_builder.py
index 42909810..66ad3250 100644
--- a/xtesting/ci/tier_builder.py
+++ b/xtesting/ci/tier_builder.py
@@ -45,11 +45,11 @@ class TierBuilder(object):
tier = tier_handler.Tier(
name=dic_tier['name'], order=dic_tier['order'],
description=dic_tier['description'])
-
for dic_testcase in dic_tier['testcases']:
testcase = tier_handler.TestCase(
name=dic_testcase['case_name'],
enabled=dic_testcase.get('enabled', True),
+ skipped=False,
criteria=dic_testcase['criteria'],
blocking=dic_testcase['blocking'],
description=dic_testcase['description'],
@@ -58,17 +58,20 @@ class TierBuilder(object):
if testcase.is_enabled():
tier.add_test(testcase)
else:
+ testcase.skipped = True
tier.skip_test(testcase)
else:
for dependency in dic_testcase['dependencies']:
kenv = dependency.keys()[0]
if not re.search(dependency[kenv], env.get(kenv)):
+ testcase.skipped = True
tier.skip_test(testcase)
break
else:
if testcase.is_enabled():
tier.add_test(testcase)
else:
+ testcase.skipped = True
tier.skip_test(testcase)
self.tier_objects.append(tier)
diff --git a/xtesting/ci/tier_handler.py b/xtesting/ci/tier_handler.py
index 11a0858e..ce9685be 100644
--- a/xtesting/ci/tier_handler.py
+++ b/xtesting/ci/tier_handler.py
@@ -97,11 +97,12 @@ class Tier(object):
class TestCase(object):
- def __init__(self, name, enabled, criteria, blocking,
+ def __init__(self, name, enabled, skipped, criteria, blocking,
description="", project=""):
# pylint: disable=too-many-arguments
self.name = name
self.enabled = enabled
+ self.skipped = skipped
self.criteria = criteria
self.blocking = blocking
self.description = description
@@ -113,6 +114,9 @@ class TestCase(object):
def is_enabled(self):
return self.enabled
+ def is_skipped(self):
+ return self.skipped
+
def get_criteria(self):
return self.criteria
diff --git a/xtesting/tests/unit/ci/test_run_tests.py b/xtesting/tests/unit/ci/test_run_tests.py
index 448b6f3f..392612bd 100644
--- a/xtesting/tests/unit/ci/test_run_tests.py
+++ b/xtesting/tests/unit/ci/test_run_tests.py
@@ -130,6 +130,8 @@ class RunTestsTesting(unittest.TestCase):
def test_run_tests_import_exception(self, *args):
mock_test = mock.Mock()
kwargs = {'get_name.return_value': 'test_name',
+ 'is_skipped.return_value': False,
+ 'is_enabled.return_value': True,
'needs_clean.return_value': False}
mock_test.configure_mock(**kwargs)
with self.assertRaises(Exception) as context:
@@ -145,6 +147,8 @@ class RunTestsTesting(unittest.TestCase):
def test_run_tests_default(self, *args):
mock_test = mock.Mock()
kwargs = {'get_name.return_value': 'test_name',
+ 'is_skipped.return_value': False,
+ 'is_enabled.return_value': True,
'needs_clean.return_value': True}
mock_test.configure_mock(**kwargs)
test_run_dict = {'module': 'test_module',
@@ -153,12 +157,47 @@ class RunTestsTesting(unittest.TestCase):
return_value=test_run_dict):
self.runner.clean_flag = True
self.runner.run_test(mock_test)
-
args[0].assert_called_with('test_name')
args[1].assert_called_with('test_module')
self.assertEqual(self.runner.overall_result,
run_tests.Result.EX_OK)
+ @mock.patch('xtesting.ci.run_tests.Runner.get_dict_by_test')
+ def test_run_tests_disabled(self, *args):
+ mock_test = mock.Mock()
+ kwargs = {'get_name.return_value': 'test_name',
+ 'is_skipped.return_value': False,
+ 'is_enabled.return_value': False,
+ 'needs_clean.return_value': True}
+ mock_test.configure_mock(**kwargs)
+ test_run_dict = {'module': 'test_module',
+ 'class': 'test_class'}
+ with mock.patch('xtesting.ci.run_tests.Runner.get_run_dict',
+ return_value=test_run_dict):
+ self.runner.clean_flag = True
+ self.runner.run_test(mock_test)
+ args[0].assert_not_called()
+ self.assertEqual(self.runner.overall_result,
+ run_tests.Result.EX_OK)
+
+ @mock.patch('xtesting.ci.run_tests.Runner.get_dict_by_test')
+ def test_run_tests_skipped(self, *args):
+ mock_test = mock.Mock()
+ kwargs = {'get_name.return_value': 'test_name',
+ 'is_skipped.return_value': True,
+ 'is_enabled.return_value': True,
+ 'needs_clean.return_value': True}
+ mock_test.configure_mock(**kwargs)
+ test_run_dict = {'module': 'test_module',
+ 'class': 'test_class'}
+ with mock.patch('xtesting.ci.run_tests.Runner.get_run_dict',
+ return_value=test_run_dict):
+ self.runner.clean_flag = True
+ self.runner.run_test(mock_test)
+ args[0].assert_not_called()
+ self.assertEqual(self.runner.overall_result,
+ run_tests.Result.EX_OK)
+
@mock.patch('xtesting.ci.run_tests.Runner.run_test',
return_value=TestCase.EX_OK)
def test_run_tier_default(self, *mock_methods):
diff --git a/xtesting/tests/unit/ci/test_tier_handler.py b/xtesting/tests/unit/ci/test_tier_handler.py
index 21670dd9..2c48ac98 100644
--- a/xtesting/tests/unit/ci/test_tier_handler.py
+++ b/xtesting/tests/unit/ci/test_tier_handler.py
@@ -25,7 +25,7 @@ class TierHandlerTesting(unittest.TestCase):
self.tier = tier_handler.Tier(
'test_tier', 'test_order', 'test_desc')
self.testcase = tier_handler.TestCase(
- 'test_name', 'true', 'test_criteria',
+ 'test_name', 'true', False, 'test_criteria',
True, description='test_desc', project='project_name')
self.testcase.str = self.testcase.__str__()
self.tier.str = self.tier.__str__()