Skip to content

Commit

Permalink
Make filter more lenient on formating
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavies-st committed Jan 22, 2024
1 parent 78efb57 commit 1d01ab5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/stpipe/crds_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ def get_multiple_reference_paths(parameters, reference_file_types, observatory):
log.set_log_time(True)

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

logging.getLogger("CRDS").addFilter(parsfilter)

Expand Down
7 changes: 3 additions & 4 deletions tests/test_crds_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@


@pytest.mark.skip(
"CRDS logs via stderr and pytest can't capture it. "
"CRDS logs in a non-standard way, and pytest can't capture it. "
"See https://github.com/pytest-dev/pytest/issues/5997"
)
def test_pars_log_filtering(capfd):
def test_pars_log_filtering(caplog):
# 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,7 +33,6 @@ def test_pars_log_filtering(capfd):
# 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-crunchyfrogstep'" not in captured.err
"Error determining best reference for 'pars-crunchyfrogstep'" not in caplog.text
)

0 comments on commit 1d01ab5

Please sign in to comment.