Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > doctesting practices

Reply
Thread Tools

doctesting practices

 
 
Alia Khouri
Guest
Posts: n/a
 
      08-27-2008
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

AK

</module>
'''
Simple doctest of a module

usage::

>>> fib(0)

0
>>> fib(1)

1
>>> fib(10)

55
>>> fib(15)

610

'''

def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n-1) + fib(n-2)


def _test(covered=False):
import doctest
if covered:
doctest.testmod()
else:
exec doctest.script_from_examples(__doc__) in globals()

if __name__ == '__main__':
_test()

</module>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
doctesting belinda thom Python 2 01-02-2007 09:33 AM
Application Folder Organization (Best Practices) Digital ASP .Net 0 06-29-2005 04:54 PM
Audio Practices Guranteed Pass Akinkawon Frierson Microsoft Certification 0 03-15-2005 06:21 AM
Re: Best Practices - VSS integration with VS.NET, migrating our Classic ASP projects news.microsoft.com ASP .Net 0 05-03-2004 08:29 PM
best practices using procedure attributes Izvra ASP .Net 0 12-23-2003 09:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57