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 = 23

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

then, e.g.:

$ py26 dt.py -v
Trying:
    foo
Expecting:
    23
ok
1 items passed all tests:
   1 tests in __main__
1 tests in 1 items.
1 passed and 0 failed.
Test passed.

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