-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-41943: Fix bug where assertLogs doesn't correctly filter messages… #22565
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
783cc7b
bpo-41898: Fix bug where assertLogs doesn't correctly filter messages…
iritkatriel 35d016b
revert fix in unittest, and fix in logging. Two previous tests (test_…
iritkatriel 9638eea
Revert "revert fix in unittest, and fix in logging. Two previous test…
iritkatriel e4f169e
📜🤖 Added by blurb_it.
blurb-it[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2020-10-07-18-36-03.bpo-41943.Pt55fT.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix bug where TestCase.assertLogs doesn't correctly filter messages by level. |
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.
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.
Note that this test is similar to the one just above it, which doesn't set the level on the log_foo logger. In that case, log_foo has level WARNING, so the message is blocked by it. But in the new test log_foo lets the message through to the root logger, which has that _CapturingHandler attached to it. But since the _CapturingHandler's level was not set, it is NOTSET which is 0 so I guess it allows all messages through. So my change sets the level of the handler to the level specified by the user.
So with my change we set the log level both on the logger and on the handler attached to it. This seems to fix this particular bug but I'm not sure the interplay between the logger's and the handler's log level is always what we would expect it to be. Here is a small script demonstrating what's going on:
As it is, all 3 log lines are emitted. If you uncomment the setLevel on the handler, only the warning and error are.