Per Erik Strandberg /cv /kurser /blog

Any good python code should be written as a module and if possible it should include some tests - doctests (see article on Wikipedia: [1]) are awesome! Download the template as a file from: [2]

See also a longer example in Python Doctest And Docstring.

#!/usr/bin/env python

"Minimal Python Module with doctest."

def hello():
    """
    Say hello.
   
    >>> hello()
    Hello World!
    """
    
    print "Hello World!"

if __name__ == '__main__':
    import doctest
    res = doctest.testmod()
    print "Tested %s cases, %s failed" % (res.attempted, res.failed)


This page belongs in Kategori Mallar
This page belongs in Kategori Test