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

[7431] Add --suppress-logger CLI option #10371

Merged
merged 12 commits into from
Oct 23, 2022

Conversation

itxasos23
Copy link
Contributor

Issue

Users want to suppress logger by name when invoking pytest.

Proposed solution

  • Added new CLI option to suppress loggers by name.
  • A null filter is added to each logger, which returns False for every log entry.

Based off https://github.com/pytest-dev/pytest/pull/7873/files from @symonk
Closes #7431

src/_pytest/logging.py Outdated Show resolved Hide resolved
src/_pytest/logging.py Outdated Show resolved Hide resolved
src/_pytest/logging.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ankostis ankostis left a comment

Choose a reason for hiding this comment

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

Thank you, indeed your test-cases cover the functionality.

@ankostis
Copy link
Contributor

ankostis commented Oct 17, 2022

Cannot merge this very useful PR, not closely involved with this project to take responsibility
@nicoddemus @bluetech, @asottile ?

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Thanks @itxasos23!

Besides the comments, we also should add this new option to https://github.com/pytest-dev/pytest/blob/main/doc/en/how-to/logging.rst.

src/_pytest/logging.py Outdated Show resolved Hide resolved
src/_pytest/logging.py Outdated Show resolved Hide resolved
testing/logging/test_reporting.py Outdated Show resolved Hide resolved
testing/logging/test_reporting.py Outdated Show resolved Hide resolved
testing/logging/test_reporting.py Outdated Show resolved Hide resolved
testing/logging/test_reporting.py Outdated Show resolved Hide resolved
src/_pytest/logging.py Outdated Show resolved Hide resolved
src/_pytest/logging.py Outdated Show resolved Hide resolved
@itxasos23
Copy link
Contributor Author

Besides the comments, we also should add this new option to https://github.com/pytest-dev/pytest/blob/main/doc/en/how-to/logging.rst. - @nicoddemus

Added docs entry; I'd like a review on wording and clarity, if possible 🙏

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Thanks @itxasos23!

changelog/7431.feature.rst Outdated Show resolved Hide resolved
@nicoddemus
Copy link
Member

Added docs entry; I'd like a review on wording and clarity, if possible

Looks good, thanks!

@nicoddemus nicoddemus merged commit 9e1804a into pytest-dev:main Oct 23, 2022
@itxasos23 itxasos23 deleted the 7431-suppress-logger branch October 23, 2022 21:26
@@ -297,6 +297,13 @@ def add_option_ini(option, dest, default=None, type=None, **kwargs):
default=None,
help="Auto-indent multiline messages passed to the logging module. Accepts true|on, false|off or an integer.",
)
group.addoption(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the new option just a command line option and not an ini option? I guess that it can't be specified in e.g. pytest.ini, right?

Copy link
Member

Choose a reason for hiding this comment

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

It is possible to use addopts to set that for every invocation if one chooses, is that what you are asking?

Copy link
Contributor

@twmr twmr Oct 24, 2022

Choose a reason for hiding this comment

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

Yes, kind of. In the logging plugin we have the add_option_ini function which is used for most parameters of the logging plugin. I think that whenever we don't use this function, we should explain in a comment why we don't use it. Even better would be an explanation in the docstring of pytest_addoption in logging.py that explains if new options should be added as ini options, as cli options or as both.

Copy link
Member

Choose a reason for hiding this comment

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

There's still time to change this, as 7.2.0 was not released yet. 😁

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.

RFE: allow to selectively disable loggers from command-line
4 participants