[py-dev] Log to a file

Simon 5kycsae02 at sneakemail.com
Thu Oct 29 07:42:17 CET 2009

On 28/10/2009, at 19:44 , holger krekel holger-at-merlinux.eu |py-dev  
+ execnet-dev| wrote:

>> Hi Holger,
>> I started looking into this a bit but ran into a problem when I
>> started to probe the py.io module.
>> I tried running the py.io examples on the website <http://codespeak.net/py/dist/io.html
>>> but when I run the py.io.StdCaptureFD example, python dies on the
>> second line:
>> stakita at okum:~$ python
>> Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
>> [GCC 4.3.3] on linux2
>> Type "help", "copyright", "credits" or "license" for more  
>> information.
>> History restored: /auto/home/stakita/.pyhistory, Max Length: 500
>>>>> import py, sys
>>>>> capture = py.io.StdCaptureFD()
> The redirect here happens for stdout, stderr and stdin is put to
> /dev/zero on the file descriptor level ...
>> stakita at okum:~$
> ... so the python interpreter immediately gets an EOL on stdin and  
> dies.

So does this mean that the example is a bit broken then?

>> My guess is that an exception is being thrown, but the captured
>> sys.stderr descriptor is not passing any meaningful traceback.
> you can call py.io.StdCaptureFD(err=True, in_=False,
> out=False) and should be able to play with writing to stderr.
>> I tried wrapping the call in try/except, but that didn't seem to  
>> help.
>> On the positive side, the problem appears to be quite reproducible.
>> Any ideas on what is going on here?
> just anoter recommendation.  Maybe it is easiest for you to implement
> a "--iocapturelog=filename" option and see to send output to
> it from the pytest_capture plugin on the py-trunk repository.
> You can start experimenting by copying the pytest_capture.py
> file somewhere into your import path and modifying it.  Your
> local version will override the builtin one.
> HTH,
> holger

Thanks for the suggestion, and here is a first pass. Attached is a  
modified version of pytest_capture.py from the 1.0.2 release.

In this file, I just push the options into the CaptureManager so that  
the command line args are available. This does mean that the config  
file options stuff is not hooked up, but at least it works from the  
command line at the moment.

Additional plugin command line options are:
     --log-file <filename>
         When used with the two capture options ('fd' and 'sys') this  
will enable pushing the stdout and stderr writes to the specified file.
         This allows appending to the file as opposed to the default  
clobber behaviour.

Does this fit with your model of how the plugin should be structured?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20091029/bb855e1b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pytest_capture.py
Type: text/x-python-script
Size: 11688 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20091029/bb855e1b/attachment.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20091029/bb855e1b/attachment-0001.html>

More information about the Pytest-dev mailing list