Skip to content

pytest caplog is incompatible with logging.config.dictConfig() #11011

Answered by erik-hasse
thebuzzstop asked this question in General
Discussion options

You must be logged in to vote

Solved it! The issue is that we had a logger called "root" in the config dictionary. Looking at your example you do too. In 3.8 and earlier, calling logger.getLogger("root") returned an otherwise ordinary logger named "root". But in 3.9 this change was introduced:

The logging.getLogger() API now returns the root logger when passed the name 'root', whereas previously it returned a non-root logger named 'root'. This could affect cases where user code explicitly wants a non-root logger named 'root', or instantiates a logger using logging.getLogger(name) in some top-level module called 'root.py'.

So with this change, caplog is adding its handler to the root logger, but then when you call di…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by nicoddemus
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: logging related to the logging builtin plugin
3 participants
Converted from issue

This discussion was converted from issue #10606 on May 17, 2023 11:19.