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...

  1. Create a script called recipe15.py that parses a set of options using Python's getopt library:
import getoptimport globimport loggingimport noseimport osimport os.pathimport pydocimport reimport sysdef usage():    print    print "Usage: python recipe15.py [command]"    print    print "t--help"    print "t--test"    print "t--suite [suite]"    print "t--debug-level [info|debug]"    print "t--package"    print "t--publish"    print "t--register"    print "t--pydoc"    printtry:    optlist, args = getopt.getopt(sys.argv[1:],                    "ht",                     ["help", "test", "suite=",                    "debug-level=", "package",                    "publish", "register", "pydoc"])except getopt.GetoptError:    # print help information and exit:    print "Invalid command found in %s" % sys.argvusage()    sys.exit(2)
  1. Create a function that ...

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