This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author p.lavarre@ieee.org
Recipients p.lavarre@ieee.org
Date 2007-12-13.14:13:13
SpamBayes Score 0.1447485
Marked as misclassified No
Message-id <1197555194.14.0.664818118617.issue1611@psf.upfronthosting.co.za>
In-reply-to
Content
SUMMARY:

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

STEPS TO REPRODUCE:

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

ACTUAL RESULTS:

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

EXPECTED RESULTS:

$ python ./tttestmod.py 
$ 

WORKAROUND:

Filter stdout.write calls from doctest.py to squelch the noise.

REGRESSION/ ISOLATION:

$ python --version
Python 2.5.1
$

Also mentioned 2006-10 in comp.lang.python at DocTestRunner.merge 
verbose,
i.e., http://groups.google.com/group/comp.lang.python/search?
group=comp.lang.python&q=DocTestRunner.merge+verbose

Not yet found in Bugs.python.org at DocTestRunner.

NOTES:

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 
stdout,
for example as below.

#!/usr/bin/env python

r""" ttestmod.py

Filter Doctest stdout a la http://wiki.python.org/moin/doctest
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
True
>>>

"""

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:
			self.out.write(bytes)

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

if __name__ == '__main__':

	import doctest

	sys.stdout = DocTestOutput()

	doctest.testmod()
	doctest.testmod()
History
Date User Action Args
2007-12-13 14:13:14p.lavarre@ieee.orgsetspambayes_score: 0.144748 -> 0.1447485
recipients: + p.lavarre@ieee.org
2007-12-13 14:13:14p.lavarre@ieee.orgsetspambayes_score: 0.144748 -> 0.144748
messageid: <1197555194.14.0.664818118617.issue1611@psf.upfronthosting.co.za>
2007-12-13 14:13:14p.lavarre@ieee.orglinkissue1611 messages
2007-12-13 14:13:13p.lavarre@ieee.orgcreate