[odl-sfc] Fix bug when getting the params for create_vnf
[functest.git] / functest / core / pytest_suite_runner.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2015 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 import testcase_base as base
11 import unittest
12 import time
13
14
15 class PyTestSuiteRunner(base.TestcaseBase):
16     """
17     This superclass is designed to execute pre-configured unittest.TestSuite()
18     objects
19     """
20     def __init__(self):
21         super(PyTestSuiteRunner, self).__init__()
22         self.suite = None
23
24     def run(self, **kwargs):
25         """
26         Starts test execution from the functest framework
27         """
28         self.start_time = time.time()
29         result = unittest.TextTestRunner(verbosity=2).run(self.suite)
30         self.stop_time = time.time()
31
32         if result.errors:
33             self.logger.error('Number of errors in test suite - ' +
34                               str(len(result.errors)))
35             for test, message in result.errors:
36                 self.logger.error(str(test) + " ERROR with " + message)
37
38         if result.failures:
39             self.logger.error('Number of failures in test suite - ' +
40                               str(len(result.failures)))
41             for test, message in result.failures:
42                 self.logger.error(str(test) + " FAILED with " + message)
43
44         # a result can be PASS or FAIL
45         # But in this case it means that the Execution was OK
46         # we shall distinguish Execution Error from FAIL results
47         # TestcaseBase.EX_RUN_ERROR means that the test case was not run
48         # not that it was run but the result was FAIL
49         exit_code = base.TestcaseBase.EX_OK
50         if ((result.errors and len(result.errors) > 0)
51                 or (result.failures and len(result.failures) > 0)):
52             self.logger.info("%s FAILED" % self.case_name)
53             self.criteria = 'FAIL'
54         else:
55             self.logger.info("%s OK" % self.case_name)
56             self.criteria = 'PASS'
57
58         self.details = {}
59         return exit_code