aboutsummaryrefslogtreecommitdiffstats
path: root/test/framework.py
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2019-12-01 22:24:28 -0500
committerDave Wallace <dwallacelf@gmail.com>2020-05-05 20:50:10 +0000
commit9beabd8afd9c9a3f302ebddaae47f7a1275faeca (patch)
tree51dc0e7982f8c8d4a26eaef0acffc0d0c8f7b5cb /test/framework.py
parent03ec134bc8f7a0180742c768bbd7dd96a81bfdfc (diff)
tests: clean up logging
Tests currently expect the logger to be poked from run_tests.py. The tests should run without any magic values. This change sets a default null logger and removes the hasattr checks for the logger. For reference, see: https://docs.python-guide.org/writing/logging/ Type: test Change-Id: I98f953d73d12d00e74b59c94a0fb8c7a625b9c44 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'test/framework.py')
-rw-r--r--test/framework.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/test/framework.py b/test/framework.py
index 9eea8bb03a5..c9d72a768bb 100644
--- a/test/framework.py
+++ b/test/framework.py
@@ -2,6 +2,7 @@
from __future__ import print_function
import gc
+import logging
import sys
import os
import select
@@ -52,6 +53,12 @@ try:
except NameError:
pass
+logger = logging.getLogger(__name__)
+
+# Set up an empty logger for the testcase that can be overridden as necessary
+null_logger = logging.getLogger('VppTestCase')
+null_logger.addHandler(logging.NullHandler())
+
PASS = 0
FAIL = 1
ERROR = 2
@@ -275,6 +282,7 @@ class VppTestCase(unittest.TestCase):
extra_vpp_punt_config = []
extra_vpp_plugin_config = []
+ logger = null_logger
vapi_response_timeout = 5
@property
@@ -1147,17 +1155,16 @@ class VppTestCase(unittest.TestCase):
time.sleep(0)
return
- if hasattr(cls, 'logger'):
- cls.logger.debug("Starting sleep for %es (%s)", timeout, remark)
+ cls.logger.debug("Starting sleep for %es (%s)", timeout, remark)
before = time.time()
time.sleep(timeout)
after = time.time()
- if hasattr(cls, 'logger') and after - before > 2 * timeout:
+ if after - before > 2 * timeout:
cls.logger.error("unexpected self.sleep() result - "
"slept for %es instead of ~%es!",
after - before, timeout)
- if hasattr(cls, 'logger'):
- cls.logger.debug(
+
+ cls.logger.debug(
"Finished sleep (%s) - slept %es (wanted %es)",
remark, after - before, timeout)
@@ -1297,22 +1304,20 @@ class VppTestResult(unittest.TestResult):
failed_dir,
'%s-FAILED' %
os.path.basename(self.current_test_case_info.tempdir))
- if self.current_test_case_info.logger:
- self.current_test_case_info.logger.debug(
+
+ self.current_test_case_info.logger.debug(
"creating a link to the failed test")
- self.current_test_case_info.logger.debug(
+ self.current_test_case_info.logger.debug(
"os.symlink(%s, %s)" %
(self.current_test_case_info.tempdir, link_path))
if os.path.exists(link_path):
- if self.current_test_case_info.logger:
- self.current_test_case_info.logger.debug(
+ self.current_test_case_info.logger.debug(
'symlink already exists')
else:
os.symlink(self.current_test_case_info.tempdir, link_path)
except Exception as e:
- if self.current_test_case_info.logger:
- self.current_test_case_info.logger.error(e)
+ self.current_test_case_info.logger.error(e)
def send_result_through_pipe(self, test, result):
if hasattr(self, 'test_framework_result_pipe'):