logging module and doctest

Peter Otten __peter__ at web.de
Thu Jan 25 03:38:41 EST 2007


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.

Peter



More information about the Python-list mailing list