From 5027784b227148074c7d04865aade868fa4a4285 Mon Sep 17 00:00:00 2001 From: Michael Hanke Date: Fri, 27 Oct 2023 11:27:47 +0200 Subject: [PATCH] Throw away INFO log messages in test runs This is an attempt to denoise the test output. Ping #503 --- datalad_next/conftest.py | 2 ++ datalad_next/tests/fixtures.py | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/datalad_next/conftest.py b/datalad_next/conftest.py index 498f893d..feef9318 100644 --- a/datalad_next/conftest.py +++ b/datalad_next/conftest.py @@ -32,6 +32,8 @@ httpbin, # session-scope HTTPBIN instance startup and URLs httpbin_service, + # session-scope redirection of log messages + reduce_logging, # session-scope, standard webdav credential (full dict) webdav_credential, # function-scope, serve a local temp-path via WebDAV diff --git a/datalad_next/tests/fixtures.py b/datalad_next/tests/fixtures.py index 254a3615..593094c4 100644 --- a/datalad_next/tests/fixtures.py +++ b/datalad_next/tests/fixtures.py @@ -23,6 +23,45 @@ lgr = logging.getLogger('datalad.next.tests.fixtures') +@pytest.fixture(autouse=True, scope="session") +def reduce_logging(): + """Reduce the logging output during test runs + + DataLad emits a large amount of repetitive INFO log messages that only + clutter the test output, and hardly ever help to identify an issue. + This fixture modifies the standard logger to throw away all INFO level + log messages. + + With this approach, such messages are still fed to and processes by the + logger (in contrast to an apriori level setting). + """ + dllgr = logging.getLogger('datalad') + # leave a trace that this is happening + dllgr.info("Test fixture starts suppressing INFO level messages") + + class NoInfo(logging.Filter): + def filter(self, record): + # it seems unnecessary to special case progress logs, moreover + # not filtering them out will make clone/fetch/push very visible + # in the logs with trivial messages + #if hasattr(record, 'dlm_progress'): + # # this is a progress log message that may trigger something + # # a test is looking for + # return True + if record.levelno == 20: + # this is a plain INFO message, ignore + return False + else: + return True + + noinfo = NoInfo() + # we need to attach the filter to any handler to make it effective. + # adding to the logger only will not effect any log messages produced + # via descendant loggers + for hdlr in dllgr.handlers: + hdlr.addFilter(noinfo) + + @pytest.fixture(autouse=False, scope="function") def tmp_keyring(): """Patch plaintext keyring to temporarily use a different storage