Skip to content

Lower the root logger's log level to --log-level instead of to NOTSET #3027

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion _pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ def __init__(self, config):
The formatter can be safely shared across all handlers so
create a single one for the entire test session here.
"""
self.log_level = get_actual_log_level(
config, 'log_level') or logging.WARNING
Copy link
Member

Choose a reason for hiding this comment

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

We might consider to use None as default; then if None, we don't touch the log level at all all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that if you pass None to logger.setLevel or handler.setLevel a TypeError is raised.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, but actually I meant to check for None before calling setLevel.

self.log_cli_level = get_actual_log_level(
config, 'log_cli_level', 'log_level') or logging.WARNING

Expand Down Expand Up @@ -287,7 +289,8 @@ def __init__(self, config):
def _runtest_for(self, item, when):
"""Implements the internals of pytest_runtest_xxx() hook."""
with catching_logs(LogCaptureHandler(),
formatter=self.formatter) as log_handler:
formatter=self.formatter,
level=self.log_level) as log_handler:
item.catch_log_handler = log_handler
try:
yield # run test
Expand Down
1 change: 1 addition & 0 deletions changelog/2977.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lower the root logger's log level to --log-level instead of to NOTSET.