When running unit tests, using the verbose flag often provides an extra level of protection against mistakes. When running from the command line, this simply means adding the v option. If you use an IDE, matters become more complicated. While you can often set your IDE to pass in the v option when running a file, this has a number of drawbacks. This code will ensure that your tests will run with the verbose option.
1 2 3 4 5 6 | #omitted unit test code.
if __name__ == "__main__":
import sys
sys.argv.append('-v')
unittest.main()
|
Since arguments are stored as a list, you can simply modify that list before calling unittest.main(). Note that there is no problem if you use the above code AND pass in the v option. (Duplicate flags are not a problem in this case.)
Alternate way to do the same thing. What about this ?
IMHO it's more elagant...
Another way to avoid modifying sys.argv.