1 # Copyright (c) 2015 All rights reserved
2 # This program and the accompanying materials
3 # are made available under the terms of the Apache License, Version 2.0
4 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 import testcase as base
13 class PyTestSuiteRunner(base.TestCase):
15 This superclass is designed to execute pre-configured unittest.TestSuite()
18 def __init__(self, **kwargs):
19 super(PyTestSuiteRunner, self).__init__(**kwargs)
23 def run(self, **kwargs):
25 Starts test execution from the functest framework
27 self.start_time = time.time()
28 result = unittest.TextTestRunner(verbosity=2).run(self.suite)
29 self.stop_time = time.time()
32 self.logger.error('Number of errors in test suite - ' +
33 str(len(result.errors)))
34 for test, message in result.errors:
35 self.logger.error(str(test) + " ERROR with " + message)
38 self.logger.error('Number of failures in test suite - ' +
39 str(len(result.failures)))
40 for test, message in result.failures:
41 self.logger.error(str(test) + " FAILED with " + message)
43 # a result can be PASS or FAIL
44 # But in this case it means that the Execution was OK
45 # we shall distinguish Execution Error from FAIL results
46 # TestCase.EX_RUN_ERROR means that the test case was not run
47 # not that it was run but the result was FAIL
48 exit_code = base.TestCase.EX_OK
49 if ((result.errors and len(result.errors) > 0)
50 or (result.failures and len(result.failures) > 0)):
51 self.logger.info("%s FAILED" % self.case_name)
54 self.logger.info("%s OK" % self.case_name)