-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
plugin: loggingrelated to the logging builtin pluginrelated to the logging builtin plugintype: enhancementnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branch
Description
A "global" log level set by log_level
cannot be overridden at the test level.
Minimal Example:
# setup.cfg
[tool:pytest]
log_level = CRITICAL
# test_example.py
import logging
def function_that_logs():
logging.debug('message')
def test_logger(caplog):
caplog.set_level(logging.DEBUG)
function_that_logs()
assert caplog.text
Running pytest-master@077d1c3
, Python 3.7.6.
It looks like this is because log_level
adjusts the level of LogCaptureHandler()
in _runtest_for_main()
whereas caplog.set_level()
adjusts the level of a specific Logger
(likely Root
).
If I add self.handler.setLevel(level)
to the end of LogCaptureFixture.set_level()
the above example passes. Is this a suitable fix (assuming the corresponding cleanup is added too)? Or is this a misuse of log_level
?
Metadata
Metadata
Assignees
Labels
plugin: loggingrelated to the logging builtin pluginrelated to the logging builtin plugintype: enhancementnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branch