469,352 Members | 2,150 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

doctesting practices

I was wondering the other day how other pythonistas incorporate
doctests into their coding practices. I have acquired the habit of
keeping an editor open in one window and an ipython instance open in
another and then using something similar to the format of the module
below. In this case, I incorporate a switch in the _test function
whereby covered=False means the doctest is still being written (and is
easy to test using the command line) and covered=True means it is
somewhat complete and ready to be incorporated into a test suite.

This still seems to me to be somewhat hackish and convoluted (execing
into globals() and all), and one wonders if there are better coding
workflows out there that specifically incorporate doctests as the
primary means of testing.

Thanks in advance for any feedback


Simple doctest of a module



def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
return fib(n-1) + fib(n-2)
def _test(covered=False):
import doctest
if covered:
exec doctest.script_from_examples(__doc__) in globals()

if __name__ == '__main__':

Aug 27 '08 #1
0 648

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

136 posts views Thread by Matt Kruse | last post: by
13 posts views Thread by john doe | last post: by
10 posts views Thread by jojobar | last post: by
1 post views Thread by Pablo | last post: by
5 posts views Thread by =?Utf-8?B?TWljaGFlbFF1aW5sYW4=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.