How to give arguments for argparse without the command line

Viewed 34

I have a program that takes 2 ints as arguments and everything works as expected in the command line. I want to be able to create a tester python file that imports this first program, calls program.main(), and pass along two ints as arguments for main. Is this possible?

1 Answers

Assign to sys.argv before calling program.main()

import sys
import program

sys.argv = ["program.py", "1", "2"]
program.main()
Related