O'Reilly logo

Python Testing Cookbook. by Bhaskar N. Das, Greg L. Turnquist

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

With the following steps, we will craft a command-line script to allow us to manage a project that includes running doctest:

  1. Create a new file called recipe25.py to put all the code for this recipe.
  1. Add code that parses a set of options using Python's getopt library:
import getoptimport globimport loggingimport noseimport osimport os.pathimport reimport sysdef usage():    print ()    print ("Usage: python recipe25.py [command]")    print ()    print ("\t--help")    print ("\t--doctest")    print ("\t--suite [suite]")    print ("\t--debug-level [info|debug]")    print ("\t--package")    print ("\t--publish")    print ("\t--register")    print ()try:    optlist, args = getopt.getopt(sys.argv[1:],            "h",           ["help", "doctest", "suite=", \ "debug-level=", "package", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required