caplog: Limit level for caplog but not for pytest UI #4000
Labels
plugin: logging
related to the logging builtin plugin
type: proposal
proposal for a new feature, often to gather opinions or design the API around the new feature
This is a feature request for the
caplog
fixture.One can use
caplog.set_level
andcaplog.at_level
to temporarily set the logging level during a test case. This sets the desired level on the target logger and resets the logger's original level after the test case (or when theat_level
context manager exits).In my experience, one usually uses
caplog
to assert that certain important (i.e. high level, such asERROR
) messages are correctly logged. Low-level (e.g.DEBUG
) messages are usually not asserted, so ignoring them viacaplog.set/at_level
makes it easier to write the assertions.However, when debugging failing test cases, these low-level messages are often very useful in figuring out what went wrong.
With the current functionality, one can either have easily written assertions or helpful low-level log messages for failing tests. It would therefore be nice to be able to limit the level only for the messages available via
caplog
but not for those displayed in the UI for failing test cases. That is,caplog.records
,caplog.record_tuples
, andcaplog.text
would only contain messages at and above the level set bycaplog.set/at_level
, but for failing test cases the UI would still show all messages based on the logger's own level.If one also wants to keep the current functionality then instead of changing
caplog.set/at_level
one could introduce a parametercaplog_only
that defaults toFalse
:This would also make this change backwards-compatible.
The text was updated successfully, but these errors were encountered: