From ae360073bfddfed066bebcbafc74e74df292ce52 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 18 Jun 2018 14:15:01 +0200 Subject: [PATCH] tests: better logging for all testcases --- tests/environment/rtu_slave.py | 9 +++------ tests/run_itests.py | 8 +++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/environment/rtu_slave.py b/tests/environment/rtu_slave.py index 0ecf462..f882077 100644 --- a/tests/environment/rtu_slave.py +++ b/tests/environment/rtu_slave.py @@ -8,6 +8,7 @@ The asynchronous server is a high performance implementation using the twisted library as its backend. This allows it to scale to many thousands of nodes which can be helpful for testing monitoring software. ''' +import logging #---------------------------------------------------------------------------# # import the various server implementations #---------------------------------------------------------------------------# @@ -26,10 +27,7 @@ class ModbusSerialServer: #---------------------------------------------------------------------------# # configure the service logging #---------------------------------------------------------------------------# - import logging - logging.basicConfig() - log = logging.getLogger() - log.setLevel(logging.DEBUG) + log = logging.getLogger("ModbusServer") serialPort = readlink('/tmp/pts1') @@ -126,9 +124,8 @@ class ModbusSerialServer: self.p.start() print("p.start done") - def kill(self): - print("Going to terminate the process, this could throw exceptions") + self.log.info("Going to terminate the process, this could throw exceptions") if self.p is not None: self.p.terminate() diff --git a/tests/run_itests.py b/tests/run_itests.py index 71d5b8b..fa2f5c8 100755 --- a/tests/run_itests.py +++ b/tests/run_itests.py @@ -106,4 +106,10 @@ class TestModbusRequests(unittest.TestCase): if __name__ == '__main__': - unittest.main() \ No newline at end of file + import logging + stdout_handler = logging.StreamHandler(sys.stdout) + logging.basicConfig(level=logging.DEBUG, + format=u'[%(asctime)s] %(name)-26s-%(levelname)-5s %(funcName)-20s:%(lineno)-4d \033[35m%(message)s\033[0m', + datefmt='%d.%m. %H:%M:%S', + handlers=[stdout_handler]) + unittest.main(verbosity=2) \ No newline at end of file