spacetelescope / stdatamodels

https://stdatamodels.readthedocs.io
Other
5 stars 25 forks source link

add filter for ValidationWarning #367

Closed braingram closed 3 days ago

braingram commented 6 days ago

This PR adds an "always" filter for ValidationWarnings at the end of the warning filter list.

This addresses an issue where for an interactive python session (using the standard python REPL) only the first call to "validate" for a particular validation error will result in a warning:

> from stdatamodels.jwst import datamodels as dm
> m = dm.ImageModel()
> m.meta.instrument._instance['detector'] = "foo"
> m.validate()
ValidationWarning: While validating...
> m.validate()
# no validation warning

This is a byproduct of the "default" python warning filter which for a particular warning based on message, category and line number will only show the warning the first time. This PR adds an "always" for ValidationWarning to override this behavior but adds it to the end of the filter list so that a user can still control these warnings (for example by using -Werror to turn all warnings into errors).

I can't sort out how we can test this due to a couple factors:

I'm going to open this for review knowing that this doesn't include a test for change. I am ok with that given the scope of the change but please let me know if anyone sorts out a way to test this.

Regtests running: https://github.com/spacetelescope/RegressionTests/actions/runs/11979991732

Tasks

news fragment change types... - ``changes/.feature.rst``: new feature - ``changes/.bugfix.rst``: fixes an issue - ``changes/.doc.rst``: documentation change - ``changes/.removal.rst``: deprecation or removal of public API - ``changes/.misc.rst``: infrastructure or miscellaneous change
codecov[bot] commented 6 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 67.56%. Comparing base (1e16207) to head (78b4664). Report is 6 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #367 +/- ## ========================================== + Coverage 67.52% 67.56% +0.03% ========================================== Files 114 114 Lines 5916 5920 +4 ========================================== + Hits 3995 4000 +5 + Misses 1921 1920 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features: