[py-dev] Log to a file
holger at merlinux.eu
Wed Oct 28 09:44:00 CET 2009
On Wed, Oct 28, 2009 at 07:22 -0000, Simon wrote:
> On 16/10/2009, at 21:23 , holger krekel holger-at-merlinux.eu |py-dev
> >> We'd also like this to happen in such a way that if the tests were to
> >> hang or hard crash halfway through, we still have the debug log.
> >> Any ideas?
> > I am not completely sure how to best implement it. Maybe extend the
> > "--capture" option to specify a filename. A naive implementation
> > would
> > only produce the test output though, not meta-information like test
> > name
> > or traceback. Maybe a bit tricky to get this working for dist-
> > testing like
> > "-n 3" but that's probably true for any impl idea for this feature.
> > what do you think?
> > Capturing is done via code in the _py/test/plugin/pytest_capture.py
> > and
> > in _py/io/capture.py (py-trunk references) - not completely trivial
> > code
> > because it works hard to play nicely with tests/apps using the
> > std logging module which assumes ownership of sys.stdout/stderr
> > stream.
> > Do you feel like giving it a try?
> > I plan for a 1.1 beta1 soon so it could be available soon.
> > best,
> > holger
> 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.
> 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.
More information about the Pytest-dev