Skip to content

Commit

Permalink
Merge pull request #523 from mih/tst-less-noise
Browse files Browse the repository at this point in the history
Throw away INFO log messages in test runs
  • Loading branch information
mih authored Oct 27, 2023
2 parents 1a3b34c + 5027784 commit d3e50bb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions datalad_next/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions datalad_next/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d3e50bb

Please sign in to comment.