Valueerror i/o operation on closed file
RonnyPfannschmidt I just hit the exact same issue as shapiy above when testing if logging output of my package is correct. What is the correct usage pattern to do this with pytest? Short answer IMO is to use pytest-catchlog which provides great integration with the logging package, including a caplog fixture to capture logging output. The problem is please correct me RonnyPfannschmidt :.
You should "undo" what logging. Thank you for your pointers! Interestingly, in my slightly more complex usecase it still didn't work correctly despite doing that. In the end, I found that removing the stream handler manually afterwards was enough to make the tests run as expected:.
Yeah I know I could do a fixture, but it's just for those two tests, if I use it more I'll definitely refactor it. No, I didn't try pytest-catchlog at first, I didn't want to incur another dependency if I could avoid it. By the way, thank you for a great tool, all you pytest devs!
Now I'll shut up and stop spamming. I was getting this error when disabling a custom logger in one test, which's state persisted to the next test. Be cautious :. This is still an issue with the latest pytest across tests e. I think the issue boils down to the fact that if you set up a Stream Handler and you enable capsys the actual output stream will be a pytest stream that will be closed and thrown away at the next test in the test suite. So when a subsequent test tries to write to it you get this error.
Adding the following fixture fixed this:. Should this be automatically done always by pytest? Granted for this to work ideally you would need to do it for all loggers, not just the root one. In this case, for me, this was enough as I was only set up a custom stream logger onto the root logger.
In an ideal world, I would expect though pytest to cleanup loggig configurations at the end tests that requested the caplog fixture. I've created to track this. Skip to content. Star 8. I ran into this when using tqdm in a django manage. Skip to content. Star New issue. Jump to bottom. Milestone no action. Copy link. What steps caused that? Notebook, very unlikely that anything called sys. You mean it only comes up once per kernel, or you can't reproduce it at all?
Let me see if I can reliability replicate this in a standalone script. Also if I run the same script in a console, it works just fine, no errors, obviously.
Consistent reproduction of Working on a 4. Ah great to know, so the issue may be fixed in 4. Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment. Could you please supply some context? For example, what does this script do? What are your thoughts on why this may be happening? What have you tried to troubleshoot this issue? I posted a solution below to help with your first problem, which seems to be indentation. I added an r in front of "C:, I placed outfile.
Now It works! However, strange files e. I think that this slows my code. Should I post a new question? I would create a smaller subset of your data to test this on until you perfect your code.
As for the file names, any idea where this is coming from? You should update your question with the current code you are using under the former code as an edit and perhaps add print statements to see where those names could be coming from — GISHuman.
Show 1 more comment.
0コメント