diff options
author | valentin boucher <valentin.boucher@orange.com> | 2017-03-12 11:08:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-03-12 11:08:06 +0000 |
commit | 11d59071a11fcec1ef9fcd323070c6d4f151c7cd (patch) | |
tree | c33348d5b8b1237519b24a04ffa12eb8eb78ee99 /functest | |
parent | d1c4c53c88e50cf566ea9677a6e250ab806c8a1c (diff) | |
parent | 6ac6937237bc03b27935f71bbb33c0abffc1e993 (diff) |
Merge "Remove raise exceptions"
Diffstat (limited to 'functest')
-rw-r--r-- | functest/core/vnf_base.py | 14 | ||||
-rw-r--r-- | functest/tests/unit/core/test_vnf_base.py | 21 |
2 files changed, 21 insertions, 14 deletions
diff --git a/functest/core/vnf_base.py b/functest/core/vnf_base.py index daf8b806..0300dd22 100644 --- a/functest/core/vnf_base.py +++ b/functest/core/vnf_base.py @@ -40,7 +40,8 @@ class VnfOnBoardingBase(base.TestcaseBase): self.tenant_description = CONST.__getattribute__( 'vnf_{}_tenant_description'.format(self.case_name)) except: - raise Exception("Unknown VNF case=" + self.case_name) + # raise Exception("Unknown VNF case=" + self.case_name) + self.logger.error("Unknown VNF case={}".format(self.case_name)) try: self.images = CONST.__getattribute__( @@ -81,7 +82,7 @@ class VnfOnBoardingBase(base.TestcaseBase): vnf_ready_time - orchestrator_ready_time, 1) except Exception: self.logger.error("Error during VNF deployment", exc_info=True) - raise Exception("Error during VNF deployment") + return base.TestcaseBase.EX_TESTCASE_FAILED # Test VNF try: @@ -94,7 +95,7 @@ class VnfOnBoardingBase(base.TestcaseBase): test_vnf_done_time - vnf_ready_time, 1) except Exception: self.logger.error("Error when running VNF tests", exc_info=True) - raise Exception("Error when running VNF tests") + return base.TestcaseBase.EX_TESTCASE_FAILED # Clean the system self.clean() @@ -178,11 +179,11 @@ class VnfOnBoardingBase(base.TestcaseBase): # TODO see how to use built-in exception from releng module def deploy_vnf(self): self.logger.error("VNF must be deployed") - raise Exception("VNF not deployed") + return base.TestcaseBase.EX_TESTCASE_FAILED def test_vnf(self): self.logger.error("VNF must be tested") - raise Exception("VNF not tested") + return base.TestcaseBase.EX_TESTCASE_FAILED def clean(self): self.logger.info("test cleaning") @@ -230,4 +231,5 @@ class VnfOnBoardingBase(base.TestcaseBase): part = inspect.stack()[1][3] self.details[part]['status'] = 'FAIL' self.details[part]['result'] = error_msg - raise Exception(error_msg) + self.logger.error("Step failure:{}".format(error_msg)) + return base.TestcaseBase.EX_TESTCASE_FAILED diff --git a/functest/tests/unit/core/test_vnf_base.py b/functest/tests/unit/core/test_vnf_base.py index e27f2164..25a74b7c 100644 --- a/functest/tests/unit/core/test_vnf_base.py +++ b/functest/tests/unit/core/test_vnf_base.py @@ -8,9 +8,11 @@ # http://www.apache.org/licenses/LICENSE-2.0 import logging +import mock import unittest from functest.core import vnf_base +from functest.core import testcase_base class VnfBaseTesting(unittest.TestCase): @@ -35,18 +37,21 @@ class VnfBaseTesting(unittest.TestCase): "result": "", "duration": 5}} - def test_deploy_vnf_unimplemented(self): - with self.assertRaises(Exception) as context: - self.test.deploy_vnf() - self.assertTrue('VNF not deployed' in context.exception) + @mock.patch('logging.Logger.error') + def test_deploy_vnf_unimplemented(self, mock): + self.assertEqual(self.test.deploy_vnf(), + testcase_base.TestcaseBase.EX_TESTCASE_FAILED) + mock.assert_called_with('VNF must be deployed') - def test_test_vnf_unimplemented(self): - with self.assertRaises(Exception) as context: - self.test.test_vnf()() - self.assertTrue('VNF not tested' in context.exception) + @mock.patch('logging.Logger.error') + def test_test_vnf_unimplemented(self, mock): + self.assertEqual(self.test.test_vnf(), + testcase_base.TestcaseBase.EX_TESTCASE_FAILED) + mock.assert_called_with('VNF must be tested') def test_parse_results(self): self.assertNotEqual(self.test.parse_results(), 0) + if __name__ == "__main__": unittest.main(verbosity=2) |