Skip to content Skip to sidebar Skip to footer

How To Use A Command Line Argument In Unittest?

For some reason I'm having issues trying to use command line arguments with my unittests. Simply put, all I want is to use env with all my tests. What am I doing wrong here? # -*-

Solution 1:

I don't actually know why... But changing main to this works:

if__name__== "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('env', default='url to test against')
    args = parser.parse_args()
    env=args.env
    mySmokeTest.env = envrunner= unittest.TextTestRunner()
    itersuite = unittest.TestLoader().loadTestsFromTestCase(mySmokeTest)
    runner.run(itersuite)

note that:

mySmokeTest.env = args.env does not work

Post a Comment for "How To Use A Command Line Argument In Unittest?"