Skip to content

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

Merged
nicoddemus merged 12 commits into
pytest-dev:mainfrom
itxasos23:7431-suppress-logger
Oct 23, 2022
Merged

nicoddemus merged 12 commits into
pytest-dev:mainfrom
itxasos23:7431-suppress-logger

Conversation

@itxasos23

Copy link
Copy Markdown
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

Comment thread src/_pytest/logging.py Outdated
Comment thread src/_pytest/logging.py Outdated
Comment thread src/_pytest/logging.py Outdated
@itxasos23
itxasos23 requested a review from ankostis October 17, 2022 18:58

@ankostis ankostis left a comment

Copy link
Copy Markdown
Contributor

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

ankostis commented Oct 17, 2022 •

Copy link
Copy Markdown
Contributor

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

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/_pytest/logging.py Outdated
Comment thread src/_pytest/logging.py Outdated
Comment thread testing/logging/test_reporting.py Outdated
Comment thread testing/logging/test_reporting.py Outdated
Comment thread testing/logging/test_reporting.py Outdated
Comment thread testing/logging/test_reporting.py Outdated
Comment thread src/_pytest/logging.py Outdated
Comment thread src/_pytest/logging.py Outdated
@itxasos23
itxasos23 force-pushed the 7431-suppress-logger branch from e9d8982 to a0012ed Compare October 23, 2022 19:51
@itxasos23

Copy link
Copy Markdown
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 🙏

@itxasos23
itxasos23 requested a review from nicoddemus October 23, 2022 20:16

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @itxasos23!

Comment thread changelog/7431.feature.rst Outdated
@nicoddemus

Copy link
Copy Markdown
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
Comment thread src/_pytest/logging.py
default=None,
help="Auto-indent multiline messages passed to the logging module. Accepts true|on, false|off or an integer.",
)
group.addoption(

Copy link
Copy Markdown
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
Copy Markdown
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?

@twmr twmr Oct 24, 2022 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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. 😁

imgbot Bot pushed a commit to kkipngenokoech/pytest that referenced this pull request Apr 18, 2026
imgbot Bot pushed a commit to kkipngenokoech/pytest that referenced this pull request Apr 18, 2026
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