[issue1611] doctest.testmod gets noisy if called more than once per SystemExit

Pat LaVarre report at bugs.python.org
Thu Dec 13 15:13:14 CET 2007


New submission from Pat LaVarre:

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()

----------
components: Library (Lib)
messages: 58533
nosy: p.lavarre at ieee.org
severity: normal
status: open
title: doctest.testmod gets noisy if called more than once per SystemExit
type: behavior
versions: Python 2.5

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1611>
__________________________________


More information about the Python-bugs-list mailing list