Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset 'seen' flag in log watcher after check #8686

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

melanieclarke
Copy link
Collaborator

@melanieclarke melanieclarke commented Aug 2, 2024

Small PR to make LogWatcher reusable for multiple messages.

Using this helper to develop tests for #8669, I found it's convenient to use the same watcher to check for different messages, but the flag needs to be reset between calls. I can do it manually, but that's failure prone. With this change, I can do something like:

log_watcher.message = 'test 1'
function_call()
log_watcher.assert_seen()

log_watcher.message = 'test 2'
function_call()
log_watcher.assert_seen()

Checklist for PR authors (skip items if you don't have permissions or they are not applicable)

  • added entry in CHANGES.rst within the relevant release section
  • updated or added relevant tests
  • updated relevant documentation
  • added relevant milestone
  • added relevant label(s)
  • ran regression tests, post a link to the Jenkins job below.
    How to run regression tests on a PR
  • All comments are resolved
  • Make sure the JIRA ticket is resolved properly

@melanieclarke melanieclarke added this to the Build 11.1 milestone Aug 2, 2024
@melanieclarke melanieclarke requested a review from a team as a code owner August 2, 2024 15:56
@melanieclarke melanieclarke requested review from braingram and removed request for a team August 2, 2024 15:56
@braingram
Copy link
Collaborator

The change looks good to me. Would you update the documentation to describe that assert_seen resets the seen flag?

Copy link

codecov bot commented Aug 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.36%. Comparing base (351157e) to head (4c50426).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8686   +/-   ##
=======================================
  Coverage   60.36%   60.36%           
=======================================
  Files         372      372           
  Lines       38325    38325           
=======================================
  Hits        23136    23136           
  Misses      15189    15189           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@braingram
Copy link
Collaborator

Thanks for opening this PR.

Alternatively, do you think documenting that the LogWatcher is one time use would work? There are reasons to strive for a single assert per test and having a one-time use watcher would work for all of these. I'm ok with either way (documenting it as one-time-use or the changes in this PR) and as this PR revealed the class documentation could be improved either way.

@melanieclarke
Copy link
Collaborator Author

I added some documentation.

Personally, I've found that single-assert-per-test is unrealistic when working with science functions. There's often a lot of setup and preprocessing that has to happen before a function can run, and sometimes the functions themselves take a long time to run. It would make unit tests take a lot longer if we could only test a single condition for each test.

Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

The expensive setup and run can be put in a fixture. Here's one example in the jwst regression tests.
https://github.com/spacetelescope/jwst/blob/master/jwst/regtest/test_fgs_image2.py

@melanieclarke melanieclarke merged commit 0970677 into spacetelescope:master Aug 2, 2024
27 checks passed
@melanieclarke melanieclarke deleted the log_watcher_seen branch August 2, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants