Fix example logs repeating themselves #16669
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Loggers repeating themselves during the Examples tests
What does this add?
This PR refactores slighly how the
stream_handler
is made and passed tologger
during all of the examples testsWhy is it needed?
When running the
no_trainer
tests, I was noticing that after each test was called the data would repeat itself. So after test 1 it was only logged once, test 2 twice, etc.For example something like the following was printed:
After further investigation, I found that this was due to the
stream_handler
being added at the start of each test. As discussed in this SO post I found, since the loggers are global we keep adding more handlers without actually removing them.As a result we kept getting multitudes of sys.stdout loggers being added, leading to these multiple print statements each time.
The fix is before each test case is written, add in our handler (e.g.):
Also unsure why this didn't quite happen during CircleCI, but this was what occurred locally for me