473,769 Members | 4,909 Online
Bytes | Software Development & Data Engineering Community
+ 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 1568
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(obje ct):
def __getattr__(sel f, name):
return getattr(sys.std out, 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(obje ct):
def __getattr__(sel f, name):
return getattr(sys.std out, 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(obje ct):
def __getattr__(sel f, name):
return getattr(sys.std out, 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
1209
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 run the tests. Here's my directory structure: /dir __init__.py /sub __init__.py
5
2161
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 feature in Python # Copyright (C) 2007 Johann C. Rocholl <johann@rocholl.net> # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the...
1
1683
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
1836
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 function is in. I'm not sure what good that does me. docstring.testmod does take an
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
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.