I use py.test to test some of my modules that contain quite a few stdlib entries. Of course, I would like the log to be logged on stdout, which was captured by py.test, so that I get all relevant log messages if the test fails.
The problem is that the logging module completes the attempt to write messages to the 'stdout' object provided by py.test after this object has been dropped by py.test. That is, I get:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.6/logging/__init__.py", line 1508, in shutdown
h.flush()
File "/usr/lib/python2.6/logging/__init__.py", line 754, in flush
self.stream.flush()
ValueError: I/O operation on closed file
If I disable capture with -s, I have no problem, but of course, this makes the test output unreadable with irrelevant logging.
Can someone tell me the correct way to integrate stdlib entry with py.test?
(I tried to look at this one , where it looks like it should work without problems, so that didn't help me)
source
share