-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Standardize event catching during repository unit tests #10153
Standardize event catching during repository unit tests #10153
Conversation
Previously we weren't mocking the global event manager in this test. This meant that we also had to clean up the global event manager afterward because changes we made to it would be carried over to other tests. Having to do so is tedious and somewhat annoying, which raised the frustration with writing unit tests that involve the event manager. Although mocking the event manager in this specific test isn't high impact, it is setting up a paradigm that allows us to more easily write unit tests involving the event manager.
…manager We want to be able to modify the global event manager during unit tests. Previously to do so we had to modify the real global event manager and then clean it up at the end of the test. In the previous commit, we updated a test to mock the global event manager, which worked successfully and meant no more cleanup was necessary. This commit takes that work and creates a fixture. Now any test that takes in that fixture as a parameter will have the global event manager be mocked.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10153 +/- ##
==========================================
- Coverage 88.65% 88.62% -0.03%
==========================================
Files 180 180
Lines 22422 22422
==========================================
- Hits 19878 19872 -6
- Misses 2544 2550 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Odd that the tests are failing here but not locally. The unit test that is failing is a unit test we'd expect to fail if the event manager changes that happen in EDIT Correction, it is broken locally. They break starting with e08c448 |
Okay so I've been doing some investigating. The tests start breaking with the change from e08c448. This is odd though because the change in that commit is renaming the test |
Reverting e08c448 does solve the problem 🤯 I mean this makes sense given that we identified that commit as the problem, but I still don't understand why the commit is problematic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some investigation details
@@ -1,7 +1,10 @@ | |||
from argparse import Namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverting this commit fixes our broken tests/unit/graph/test_selector.py::test_run_specs[a,b--]
test problem. I don't understand why.
set_from_args(args, {}) | ||
setup_event_logger(get_flags()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One theory I had was that although this commit primarily just moves the test, I also made one small change which is highlighted here. Specifically, in this test previously, these methods were called via the module instead of directly. That is these two lines were
flags.set_from_args(args, {})
setup_event_logger(flags.get_flags())
However changing these lines back to what they were and the the associated import did not solve the broken test issue we're seeing 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed PR description!
For CI breaking I think it might be changing the name caused order of test running changed |
Good timing! I just reached the same conclusion 😂
|
Previously we had started _mocking_ the global event manager. We did this because we though that meant anything we did to the global event manager, including modifying it via things like `setup_event_logger`, would be automatically cleaned up at the end of any test using the fixture because the mock would go away. However, this understanding of fixtures and mocking was incorrect, and the global event manager wouldn't be properly isolated/reset. Thus we changed to fixture to instead cleanup the global event manager before any test that uses it and by using `autouse=True` in the fixture definition we made it so that every unit test uses the fixture. Note this will no longer be viabled if we every multi-thread our unit testing as the event manager isn't actually isolated, and thus two tests could both modify the event manager at the same time.
Turns out that mocking the global event manager wasn't isolating the event manager by test. Which is unfortunate. We now instead cleanup the event manager before every unit test. Which isn't as nice, but gets the job done. |
resolves #9947
Problem
Previously if we modified the global event manager during unit tests, we then had to clean up the event manager at the end of the test. No clean up necessary. We also moved the
EventCatcher
classSolution
always_clean_event_manager
to the unit test suiteautouse=True
the fixture is used for every unit test. Thus every unit test will have clean state (so long as we aren't multi-threading our unit tests, which we currently don't)EventCatcher
class totests.utils
EventCatcher.catch
can be added to the callbacks of the event manager to check that certain event types happenChecklist