473,473 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

logging module and doctest

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

Jan 25 '07 #1
3 1557
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
Jan 25 '07 #2
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
Jan 25 '07 #3
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

Jan 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: davidlmontgomery | last post by:
I'm trying to use both nosetests and doctest with the tests pulled out into a separate file. My problem is that it seems that I need to use different import statements depending on from where I...
5
by: Johann C. Rocholl | last post by:
The following is my first attempt at adding a taint feature to Python to prevent os.system() from being called with untrusted input. What do you think of it? # taint.py - Emulate Perl's taint...
1
by: Joe Strout | last post by:
I've been using docstring to exercise each of my modules, with code like this: def _test(): import doctest doctest.testmod() if __name__ == "__main__": _test()
2
by: Joe Strout | last post by:
Some corrections, to highlight the depth of my confusion... On Nov 11, 2008, at 9:10 PM, Joe Strout wrote: Actually, it does not. And no, it isn't; it's the NAME of the module the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.