logging module and doctest

Gary Jefferson garyjefferson123 at yahoo.com
Thu Jan 25 16:22:18 EST 2007


Peter Otten wrote:
> 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

I was creating the StreamHandler inside doctest.  Turns out, however,
that I hadn't imported 'sys', and so it didn't work.  Its a little
strange that this didn't result in an error, but there you have it.

Thanks for the tip that led me to discover this.

Gary




More information about the Python-list mailing list