Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > logging module and doctest

Reply
Thread Tools

logging module and doctest

 
 
Gary Jefferson
Guest
Posts: n/a
 
      01-25-2007
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. Is there any way to
make these work together?

Gary

 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      01-25-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
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      01-25-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
 
Reply With Quote
 
Gary Jefferson
Guest
Posts: n/a
 
      01-25-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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
trace module and doctest skip@pobox.com Python 1 11-22-2007 09:31 PM
nose, doctest, and module names in subpackages davidlmontgomery@gmail.com Python 0 09-06-2006 01:27 AM
Re: Logging to a file and closing it again properly (logging module) Christoph Haas Python 1 06-14-2006 08:47 AM
Logging to a file and closing it again properly (logging module) Christoph Haas Python 0 06-12-2006 09:58 PM
[RFC] DocTest module Nicholas Wieland Ruby 2 06-01-2005 12:01 PM



Advertisments