[py-dev] using logging in py.test

holger krekel holger at merlinux.eu
Sun Sep 30 20:56:43 CEST 2012


Hi Anton,

On Sun, Sep 30, 2012 at 19:16 +0300, Anton P wrote:
> Hi All,
> 
> I'd like to use standard logging module with py.test. Messages
> generated from test functions are visible on stdout if -s option is
> set. But log messages generated from conftest.py or other custom
> modules used inside test function are not visible on stdout but
> visible in captured stdout in case -s option isn't set.
>
> I want to see all the messages from all modules on stdout, not only
> from test function.

An initial conftest.py file is loaded very early and pytest uses
unconditional capturing.  This goes back to a request from the PyPy
folks who start GCC at this stage and otherwise see lots of stuff.
If this proves to be a problem we have to see how to make it conditional.
Problem is that the conftest.py often add command line options and thus
need to to be loaded before opts are parsed (and thus "-s").
If logging is active during conftest.py import-time it will see the
captured stream and probably record it and use it from there on.
As the captured stream is not analyzed/used further in the case of "-s"
it is kind of lost, loosing the logging messages.

Potential solutions:

- try to avoid doing calls/imports of logging during conftest.py import-time.
- try out pytest-logging plugin to see if it helps
- program a PYTEST_NOCAPTURE environement setting to pytest to allow switching
  off capturing totally

best,
holger

That 
> Thank you in advance!
> -Anton
> _______________________________________________
> py-dev mailing list
> py-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/py-dev
> 



More information about the Pytest-dev mailing list