Skip to content

Commit

Permalink
Fix filtering message for leading space
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavies-st committed Jan 22, 2024
1 parent 67b56c9 commit 78efb57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/stpipe/crds_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
directly in modules other than this crds_client so that dependency order and
general integration can be managed here.
"""
import logging
import re

import crds
Expand Down Expand Up @@ -50,10 +51,13 @@ def get_multiple_reference_paths(parameters, reference_file_types, observatory):

log.set_log_time(True)

def filter_pars_errors(record):
return not record.startswith("Error determining best reference for 'pars-")
def parsfilter(record):
if not record.getMessage().strip().startswith(
"Error determining best reference for 'pars-"
):
return True

log.prepend_crds_filter(filter_pars_errors)
logging.getLogger("CRDS").addFilter(parsfilter)

return _get_refpaths(parameters, tuple(reference_file_types), observatory)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_crds_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"CRDS logs via stderr and pytest can't capture it. "
"See https://github.com/pytest-dev/pytest/issues/5997"
)
def test_pars_log_filtering(caplog):
def test_pars_log_filtering(capfd):
# A bogus pars- reffile will raise an exception in CRDS
with pytest.raises(Exception, match="Error determining best reference"):
crds_client.get_multiple_reference_paths(
Expand All @@ -33,6 +33,7 @@ def test_pars_log_filtering(caplog):
# https://github.com/pytest-dev/pytest/issues/5997
# So don't rely on this test passing (currently) to be actually testing what
# you think it is.
captured = capfd.readouterr()
assert (
"Error determining best reference for 'pars-snowblindstep'" not in caplog.text
"Error determining best reference for 'pars-crunchyfrogstep'" not in captured.err
)

0 comments on commit 78efb57

Please sign in to comment.