doctest -> unittest

Michele Simionato mis6 at pitt.edu
Mon Aug 4 23:34:44 CEST 2003


Just today I have experimented with the new doctest -> unittest
feature of Python 2.3. It works quite well, but I find the output way
too much noisy. For instance

#doctester.py

def example():
    """
    >>> 1+1
    1
    """

import doctest,unittest,__main__
suite = doctest.DocTestSuite(__main__)
unittest.TextTestRunner().run(suite)

gives the following result:

E
======================================================================
ERROR: doctest of __main__.example
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.3/unittest.py", line 413, in runTest
    self.__testFunc()
  File "/usr/local/lib/python2.3/doctest.py", line 1358, in runit
    _utest(tester, name, doc, filename, lineno)
  File "/usr/local/lib/python2.3/doctest.py", line 1308, in _utest
    raise DocTestTestFailure('Failed doctest test for %s\n'
DocTestTestFailure: Failed doctest test for __main__.example
  File "doctester.py", line 2, in example

*****************************************************************
Failure in example: 1+1
from line #1 of __main__.example
Expected: 1
Got: 2


----------------------------------------------------------------------
Ran 1 test in 0.013s

FAILED (errors=1)

It is too long for my taste, is there a way of turning off the
traceback which is confusing more than useful?

            
     Michele




More information about the Python-list mailing list