logging module and doctest

Peter Otten __peter__ at web.de
Thu Jan 25 06:05:39 EST 2007


Peter Otten wrote:

> Gary Jefferson wrote:
> 
>> I've written a logging.filter and would like to use doctest on it
>> (using a StreamHandler for stdout), but this doesn't seem possible.
>> Output from the logger seems to disappear (running the doctest strings
>> through the interpreter as-is yields expected results).  I assume this
>> is because doctest does something with logging.
> 
> It redirects stdout to a StringIO subclass to capture the output.
> 
>> Is there any way to make these work together?
> 
> Using the StreamHandler with something like
> 
> class WrapStdOut(object):
>     def __getattr__(self, name):
>         return getattr(sys.stdout, name)
> 
> instead of sys.stdout directly should work.

Or create the StreamHandler inside your doctest where sys.stdout is already
redirected.

Peter



More information about the Python-list mailing list