Skip to content

Commit

Permalink
Add unit test, but skip because of pytest bug or crds logging bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavies-st committed Jan 19, 2024
1 parent 0254e23 commit 67b56c9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/stpipe/crds_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
general integration can be managed here.
"""
import re
import logging

import crds
from crds.core import config, crds_cache_locking, heavy_client, log
Expand Down Expand Up @@ -52,9 +51,8 @@ def get_multiple_reference_paths(parameters, reference_file_types, observatory):
log.set_log_time(True)

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

log.prepend_crds_filter(filter_pars_errors)

return _get_refpaths(parameters, tuple(reference_file_types), observatory)
Expand Down
38 changes: 38 additions & 0 deletions tests/test_crds_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest

from stpipe import crds_client


@pytest.mark.skip(
"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):
# 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(
parameters={
"meta.instrument.detector": "NRCA1",
"meta.instrument.filter": "F140M",
"meta.instrument.name": "NIRCAM",
"meta.instrument.pupil": "CLEAR",
"meta.observation.date": "2012-04-22",
"meta.subarray.name": "FULL",
"meta.subarray.xsize": 2048,
"meta.subarray.xstart": 1,
"meta.subarray.ysize": 2048,
"meta.subarray.ystart": 1,
"meta.telescope": "JWST",
},
reference_file_types=["pars-crunchyfrogstep"],
observatory="jwst",
)

# The following will always be true because of a bug in how pytest handles
# oddball logging setups, as used by crds. See issue
# 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.
assert (
"Error determining best reference for 'pars-snowblindstep'" not in caplog.text
)

0 comments on commit 67b56c9

Please sign in to comment.