diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2017-05-18 16:40:13 +0200 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2017-05-18 16:55:05 +0200 |
commit | 510a5cfda3b375b432e0ed17a61e34de969b520c (patch) | |
tree | 832399d72d615247bd55a580b136f58ae28cc3fe | |
parent | 08cb7e1e62d1485f3430a1e1e027c9c6d4e9f94a (diff) |
Use logger instead of printing in console
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 <cedric.ollivier@orange.com>
-rw-r--r-- | functest/core/pytest_suite_runner.py | 16 |
1 files 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: |