I'm trying to use the argparse
library to guide the main module ( __main__
) between two possible executions:
import unittest
import argparse
arg = argparse.ArgumentParser(description='Execution type')
arg.add_argument('--type', action='store', dest='argument', type=int, default=0,
required=False, help='Chose the execution type (0=application, 1=unittest)')
options = arg.parse_args()
def main():
pass
def run_tests():
from tests import tests_models, tests_dbconnections, tests_dals
suit = unittest.TestSuite()
suit.addTest(unittest.makeSuite(tests_models.TestPerson))
suit.addTest(unittest.makeSuite(tests_models.TestClient))
suit.addTest(unittest.makeSuite(tests_dbconnections.TestPgSqlConnection))
suit.addTest(unittest.makeSuite(tests_dals.TestPgSqlDal))
return suit
if __name__ == '__main__':
if options.argument:
unittest.main(defaultTest='run_tests', verbosity=2)
else:
main()
But when running: python3 start.py --type 1
I get an error stating that the --type
argument is not recognized:
usage: start.py [-h] [-v] [-q] [--locals] [-f] [-c] [-b] [tests [tests ...]]
start.py: error: unrecognized arguments: --type