I have a python project with the following structure
test/ # unit tests to be run with nosetest
bin/ # utilities written in python to be installed
packagename/ # code for the package
For instance, bin/python_command
might contain:
@cmdline.command(usage='subcommand1 description')
def cmd_mysubcommand1(opts, args):
'''Code for python_command mysubcommand1'''
if __name__ == '__main__':
cmdline.main('Description of python_command')
Where cmdline is simply a library to help with the boilerplate code of parsing arguments and subcommand.
The question is, what's considered the best practice to unittest all the subcommands of bin/python_command
(cmd_mysubcommand1
in particular) by including a test in the test
directory? (i.e. they should be integrated in my current unittest suite).
Ideally, I would like to provide the textual command line of each command instead of specifically testing the final subcommand functions (to check that parsing of subcommands is working properly).
I have just read about scripttest but I don't know if it integrates well with the unittest python library and whether it supports mocking some of the objects used in the subcommands (which is a must for me).