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

TST: clean up pytest spam, warnings #70

Merged
merged 3 commits into from
Nov 18, 2024
Merged

Conversation

ZLLentz
Copy link
Member

@ZLLentz ZLLentz commented Nov 16, 2024

Description

  • Add shutdown method to ActionNode to clean up the worker on shutdown. py_trees describes this as something like "the opposite of setup" so since we set the worker up in setup, this seems like the canonical place to clean up the worker.
  • Tweak ActionNode's logic so it only cleans up the worker once.
  • Create a helper for the test suite that can be used to register behavior trees and nodes for cleanup at the end of a unit test. This will effectively stop the workers between tests.
  • Apply this helper to all the tests that need it.
  • Register a dummy "flaky" mark

Motivation and Context

  • Stopping work with the atexit hook is correct and necessary, but causes issues (spam) in pytest due to some sort of cleanup ordering that I wasn't able to pin down.
  • In other cases (qtbot) there is precedence for making sure each test cleans itself up.
  • The flaky mark is used in caproto and comes from pytest-rerunfailures. Since we don't want to use flaky tests, instead I opted to register the mark so pytest would stop complaining about it existing.

How Has This Been Tested?

Unit tests still work
Unit tests no longer spam on exit

Where Has This Been Documented?

Release notes

Pre-merge checklist

  • Code works interactively
  • Code follows the style guide
  • Code contains descriptive docstrings, including context and API
  • New/changed functions and methods are covered in the test suite where possible
  • Test suite passes locally
  • Test suite passes on GitHub Actions
  • Ran docs/pre-release-notes.sh and created a pre-release documentation page
  • Pre-release docs include context, functional descriptions, and contributors as appropriate

@ZLLentz ZLLentz marked this pull request as ready for review November 16, 2024 01:34
Copy link
Contributor

@tangkong tangkong left a comment

Choose a reason for hiding this comment

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

Can't complain with the results, this works well for me.

I originally did some messing with caplog in the conftest.central_logging_setup as an attempt to also avoid the spam, but this is a much more robust way to handle things. We could potentially remove that call, but I didn't see any change in behavior when I tried removing it (invoking pytest -s)

@tangkong
Copy link
Contributor

Also I dig the fixture. I wondered if it was possible to register nodes more auto-magically, but I think that's more work than it's worth (and also I'm already used to qtbot so I can't complain)

Copy link
Collaborator

@joshc-slac joshc-slac left a comment

Choose a reason for hiding this comment

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

Very good work. I could imagine this notion of BTCleaner being reused, when this comes up we can remove it from conftest

@ZLLentz
Copy link
Member Author

ZLLentz commented Nov 18, 2024

I wondered if it was possible to register nodes more auto-magically

I certainly tried! But it's not so easy unless we start registering them at init time.

@ZLLentz ZLLentz merged commit e6c6dc3 into pcdshub:master Nov 18, 2024
7 checks passed
@ZLLentz ZLLentz deleted the tst_end_spam branch November 18, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants