Replies: 1 comment
-
|
From the docs and the older issues, I would not treat this as expected behavior for the basic case. As I understand it:
So this should work: import logging
def test_debug_logging(caplog):
caplog.set_level(logging.DEBUG)
logging.debug("debug message")
assert "debug message" in caplog.textIf this minimal example fails on pytest 9.0.2 with If the minimal example works but your real project does not, I would check two common logging gotchas First, make sure the root logger handlers are not being replaced during the test or app initialization. The Second, check whether your application logger has import logging
logger = logging.getLogger("myapp")
def test_debug_logging(caplog):
caplog.set_level(logging.DEBUG, logger="myapp")
logger.debug("debug message")
assert "debug message" in caplog.textSo the short answer is: the basic behavior you describe should not be expected after #7340. If a minimal root-logger repro fails, it is likely a regression. If only your project fails, I would first look for logging reconfiguration or non-propagating named loggers |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I see there are a number of issues on the tracker around this, both open and closed, with some closed ones implying this behaviour should no longer be occurring. I'd like to get some clarity on the current status of things and any expected changes coming up.
I am currently using pytest 9.0.2.
Currently if, for example,
log_levelin the ini file is set toINFOand a test callscaplog.set_level(logging.DEBUG)(or uses the equivalentat_levelcontext manager), this does not log any messages at theDEBUGlevel during the test. The globalINFOsetting still applies.When I went looking for answers on this I found #7133, which looked like this exact problem and seemed to have already been solved in pull request #7340. Unless I'm missing something, I still have the same issue though. I see there are other open issues such as #7162 which seem to be talking about the same/a similar thing, but as I dig around and find more of them they get a bit further into the pytest internals than I'm familiar with as a user rather than a developer of the package.
Is what I'm seeing expected behaviour, or did the bug from 6 years ago rear its head again at some point?
Beta Was this translation helpful? Give feedback.
All reactions