How to test python snippets in my documents?

Matthew Wilson matt at tplus1.com
Tue May 26 10:49:29 EDT 2009


I'm using a homemade script to verify some code samples in my
documentation.  Here it is:

    #! /usr/bin/env python2.6

    # vim: set expandtab ts=4 sw=4 filetype=python:

    import doctest, os, sys

    def main(s):
        "Run doctest.testfile(s, None)"

        return doctest.testfile(s, None)

    if __name__ == "__main__":
        for x in sys.argv[1:]:
            print "testing code excerpts in %s..." % x
            print main(x)


The script checks all the files listed as arguments.  This is OK, but is
there anything better?




More information about the Python-list mailing list