From 510a5cfda3b375b432e0ed17a61e34de969b520c Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Thu, 18 May 2017 16:40:13 +0200 Subject: Use logger instead of printing in console MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It modifies pytest_suite_runner.py to dump unit test results in functest.log via logging. Change-Id: Ic4e7567c5e52e00ad0e485ccb070029b135041b2 Signed-off-by: Cédric Ollivier --- functest/core/pytest_suite_runner.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/functest/core/pytest_suite_runner.py b/functest/core/pytest_suite_runner.py index 0dd860d2..a6e47660 100644 --- a/functest/core/pytest_suite_runner.py +++ b/functest/core/pytest_suite_runner.py @@ -8,8 +8,10 @@ # pylint: disable=missing-docstring import logging -import unittest import time +import unittest + +import six from functest.core import testcase @@ -19,6 +21,7 @@ class PyTestSuiteRunner(testcase.TestCase): This superclass is designed to execute pre-configured unittest.TestSuite() objects """ + def __init__(self, **kwargs): super(PyTestSuiteRunner, self).__init__(**kwargs) self.suite = None @@ -30,11 +33,18 @@ class PyTestSuiteRunner(testcase.TestCase): """ try: name = kwargs["name"] - self.suite = unittest.TestLoader().loadTestsFromName(name) + try: + self.suite = unittest.TestLoader().loadTestsFromName(name) + except ImportError: + self.logger.error("Can not import %s", name) + return testcase.TestCase.EX_RUN_ERROR except KeyError: pass self.start_time = time.time() - result = unittest.TextTestRunner(verbosity=2).run(self.suite) + stream = six.StringIO() + result = unittest.TextTestRunner( + stream=stream, verbosity=2).run(self.suite) + self.logger.debug("\n\n%s", stream.getvalue()) self.stop_time = time.time() if result.errors: -- cgit 1.2.3-korg