-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
clear root log handlers between tests #2159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Evon your proposed change is not something we can release in a bugfix release I suspect this can only be done correct in a full logging integration |
@r0fls first of all thanks for taking the time to write this PR. Since pytest doesn't currently handle logging at all, I suggest to use the To me it feels weird to bake into If |
Thanks @RonnyPfannschmidt and @nicoddemus for the feedback, and explaining your stance. Yes, this was more of an attempt to get a discussion going and demonstrate the issue, so I understand this isn't suitable to merge. If this change could be implemented at the module/file level (so, only clear the root logger between separate test files), then I would be far more adamant about it being a good idea. However I could not find a straightforward way to do that. So, I agree we can close this since catchlog does have support for this using their def test_foo(caplog):
caplog.set_level(logging.CRITICAL, logger='root.baz')
pass Whether or not to add full blown logging support I would see as a separate question, yet I also agree it may not be necessary with such nice plugins. I wasn't aware of those, thank you. I was shocked when logging settings were shared between separate test files. So I do think this is a pretty annoying bug. Once discovered, it's definitely easy to handle from a user's perspective. For the first 10-20 minutes of test agony though... it was a bit perplexing. Since pytest is really the one at fault here, it does feel like we should do something to prevent users from the confusion that I encountered. However if the fix is substantial, I wouldn't prioritize it. In that case I do think it would be worth adding a description of the issue here, just for the record: http://docs.pytest.org/en/latest/faq.html |
I think pytest-catchlog already handles clearing the logs between the tests even when not using the @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_teardown(self, item):
yield
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
Definitely. Documentation is one of the areas we really need to improve and help is welcome. In fact, once eisensheng/pytest-catchlog#19 is solved I'm thinking it might be a good idea to add an explicit page to the official docs named "Logging" which explains that |
Given the context above, are you OK with closing this PR @r0fls? |
Yup! Thank you |
It would be worth to add here that nowadays |
Addresses #2158 which qualifies as a bug to me. Hence target should be master. The implementation is not ideal: it clears module level logging settings, whereas ideally those would be preserved. However, I think it's better than the current behavior, where the module settings overlap between different tests.