Title: doctest.testmod gets noisy if called more than once per SystemExit
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.5
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: gvanrossum, ncoghlan,, r.david.murray, tim.peters
Priority: normal Keywords:

Created on 2007-12-13 14:13 by, last changed 2009-03-14 01:50 by ncoghlan. This issue is now closed.

Messages (5)
msg58533 - (view) Author: Pat LaVarre ( Date: 2007-12-13 14:13

Calling doctest.testmod more than once before SystemExit spews stderr 
messages such as "*** DocTestRunner.merge: '__main__' in both testers; 
summing outcomes"


$ cat 
import doctest
doctest.testmod() # 1
doctest.testmod() # 2
doctest.testmod() # 3


$ python ./ 
*** DocTestRunner.merge: '__main__' in both testers; summing outcomes.
*** DocTestRunner.merge: '__main__' in both testers; summing outcomes.


$ python ./ 


Filter stdout.write calls from to squelch the noise.


$ python --version
Python 2.5.1

Also mentioned 2006-10 in comp.lang.python at DocTestRunner.merge 

Not yet found in at DocTestRunner.


We can reasonably expect newbies to doctest random things
that need to be doctested more than once.

We can't reasonably expect newbies to know to how to filter doctest 
for example as below.

#!/usr/bin/env python


Filter Doctest stdout a la
to call doctest.testmod more than once per SystemExit
without producing noise.

>>> import random
>>> import sys
>>> die = random.randint(1, 6)
>>> print >>sys.stderr, die
>>> die == 6


import sys

class DocTestOutput:

	def __init__(self, out = sys.stdout):

		self.out = out
		self.write = self.writeOut
		self.quietly = False

	def writeOut(self, bytes):

		head = "*** DocTestRunner.merge: '__main__"
		tail = "' in both testers; summing outcomes."

		if bytes.startswith(head):
			if bytes.endswith(tail):
				self.quietly = True

		if not self.quietly:

		if 0 <= bytes.find('\n'):
			self.quietly = False

if __name__ == '__main__':

	import doctest

	sys.stdout = DocTestOutput()

msg58543 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-12-13 18:05
I suspect that doctest was simply not intended to be used this way.

Maybe Tim remembers more?
msg83281 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-03-07 16:04
The offending output lines were commented out by Nick Coghlan in
commit 67790 with the comment "Don't print here by default, since doing
so breaks some of the buildbots".  The actual code change disables the
output rather than changing the default, so perhaps it is not quite what
Nick intended.  However, either way the intent seems to be to not
generate this output normally, which would mean that this bug could be
considered fixed in the trunk.
msg83536 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-03-13 21:13
Nick, is the change you made to Lib/, commenting out the print
"*** DocTestRunner.merge:" message, intended to be permanent?  If so, we
can close this bug.
msg83568 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-03-14 01:50
I believe I commented it out when we were trying to get the buildbots
green before releasing 2.6. (The fact that trips over it
does suggest there are legitimate reasons for calling doctest.testmod()
more than once in a single test suite though)

It looked like some debugging code that was accidentally left in to me
(putting random stuff on the screen in a test tool that monitors what is
written to stdout is less than helpful...)

Since 2.5 is only getting security fixes now and later versions don't
suffer from the issue, I'm closing this one as "out of date".
Date User Action Args
2009-03-14 01:50:10ncoghlansetstatus: open -> closed

messages: + msg83568
resolution: out of date
2009-03-13 21:13:26r.david.murraysetnosy: + ncoghlan
messages: + msg83536
2009-03-07 16:04:26r.david.murraysetnosy: + r.david.murray
messages: + msg83281
2007-12-13 18:05:15gvanrossumsetassignee: tim.peters
messages: + msg58543
nosy: + gvanrossum, tim.peters
2007-12-13 14:13:14p.lavarre@ieee.orgcreate