Skip to content Skip to sidebar Skip to footer

Python Using Doctest On The Mainline

Hello i was wondering if it is possible and if so how? to do doctests or something similar from the mainline, instead of testing a function as is described in the doctest docs i.e.

Solution 1:

doctest is not limited to testing functions. For example, if dt.py is:

'''
  >>> foo
  23
'''

foo = 23if __name__ == '__main__':
    import doctest
    doctest.testmod()

then, e.g.:

$py26dt.py-vTrying:fooExpecting:23ok1 items passed all tests:1testsin__main__1testsin1items.1passedand0failed.Testpassed.

(works just as well without the -v, but then it wouldn't have much to show: just silence;-). Is this what you're looking for?

Post a Comment for "Python Using Doctest On The Mainline"