Merge "Add host aggregate / av zones util functions"
[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         if (result.errors and len(result.errors) > 0) \
45                 or (result.failures and len(result.failures) > 0):
46             self.logger.info("%s FAILED" % self.case_name)
47             self.criteria = 'FAIL'
48             exit_code = base.TestcaseBase.EX_RUN_ERROR
49         else:
50             self.logger.info("%s OK" % self.case_name)
51             exit_code = base.TestcaseBase.EX_OK
52             self.criteria = 'PASS'
53
54         self.details = {}
55         return exit_code