I have a foo.py using argparse to get command line parameters for the main() function.
""" foo.py """
import argparse
def main():
parser = argparse.ArgumentParser(description='test')
parser.add_argument('--all', '-a', action='store_true', help='all')
args = parser.parse_args()
if args.all:
pass
if __name__ == '__main__':
main()
And I have to test this main() function on another Python script bar.py. My question is how to pass parameters in bar.py. My current solution is changing the sys.argv. Looking for better solution.
""" bar.py """
import sys
import foo
if __name__ == '__main__':
sys.argv.append('-a')
foo.main()
foo.pyintobar.py? Why not just move theparserintobar.py?