-
Notifications
You must be signed in to change notification settings - Fork 18
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
I/O operation on closed file after monkeypatching logging.root.handlers #41
Comments
Thank you for such a detailed report! I can't tell for sure what the actual reason is, but I suspect that the following steps could lead to the error in question:
At this point we've got the closed handler leaked through the We could add a (rather dirty, IMHO) workaround, that would remove the handler from the very list it was originally attached to, but just doesn't feel to be the right solution... |
I was under impression, that pytest-catchlog would attach only in tests, which use caplog fixture, but it seems it's not the case. In any case, my workaround was to delete all existing As a workaround, I've modified Removed:
And added: from pytest_catchlog import LogCaptureHandler
for h in logging.root.handlers:
if isinstance(h, LogCaptureHandler):
logging.root.removeHandler(h) |
Yes, it needs a handler for every test case in order to provide proper reporting section in case of a test failure. |
sorry to intrude. it appears like I am suffering from that, too. is there a workaround for that? |
@markfink did you try my workaround #41 (comment) |
@sashkab thank you for the advice. I understand that this workaround needs to be applied within every test which is not really an option for me. Do you think it works to wrap the "caplog" fixture into like |
I've ran into strange issue with pytest-catchlog. I have a fairly large test suite, and one of the tests has to run without any loggers in order to test functionality. I use monkeypatch to patch it:
I've setup test repository -- https://github.com/sashkab/catchlog-failure, but here are tests:
Test
test_one
passes and works as expected:Then I've got second test --
test_two
, which requires logger and it passes by itself perfectly fine.But when I try to run both of tests together, I end up with the following error:
Here is traceback for easier reading:
So, it seems like pytest-catchlog doesn't properly handle the case where
logging.root.handlers
where monkeypatched in the tests.The text was updated successfully, but these errors were encountered: