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
8 # http://www.apache.org/licenses/LICENSE-2.0
10 import testcase_base as base
15 class PyTestSuiteRunner(base.TestcaseBase):
17 This superclass is designed to execute pre-configured unittest.TestSuite()
21 super(PyTestSuiteRunner, self).__init__()
24 def run(self, **kwargs):
26 Starts test execution from the functest framework
28 self.start_time = time.time()
29 result = unittest.TextTestRunner(verbosity=2).run(self.suite)
30 self.stop_time = time.time()
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)
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)
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'
55 self.logger.info("%s OK" % self.case_name)
56 self.criteria = 'PASS'