This is an automated email from the ASF dual-hosted git repository. jdanek pushed a commit to branch jd_tryout in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
commit 021f5b05b045ec5526008e166b65e09589ee4c47 Author: Jiri Daněk <[email protected]> AuthorDate: Sun Jan 30 18:04:12 2022 +0100 DISPATCH-2323 Add Pytest-compatible logging displayed on test failure --- tests/system_test.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/system_test.py b/tests/system_test.py index 46a7eb5..877105b 100755 --- a/tests/system_test.py +++ b/tests/system_test.py @@ -28,7 +28,8 @@ Features: - Sundry other tools. """ -from typing import Callable +import logging +from typing import Callable, Optional import errno import sys @@ -1406,17 +1407,20 @@ class Logger: """ Record an event log for a self test. May print per-event or save events to be printed later. + Pytest will automatically collect the logs and will dump them for a failed test Optional file opened in 'append' mode to which each log line is written. """ def __init__(self, - title="Logger", - print_to_console=False, - save_for_dump=True, - ofilename=None): + title: str = "Logger", + print_to_console: bool = False, + save_for_dump: bool = True, + python_log_level: Optional[int] = logging.DEBUG, + ofilename: Optional[str] = None) -> None: self.title = title self.print_to_console = print_to_console self.save_for_dump = save_for_dump + self.python_log_level = python_log_level self.logs = [] self.ofilename = ofilename @@ -1427,6 +1431,8 @@ class Logger: if self.print_to_console: print("%s %s" % (ts, msg)) sys.stdout.flush() + if self.python_log_level is not None: + logging.log(self.python_log_level, f"{ts} {self.title}: {msg}") if self.ofilename is not None: with open(self.ofilename, 'a') as f_out: f_out.write("%s %s\n" % (ts, msg)) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
