title: How to pass parameters to python function using argparse?
body: <p>I have a foo.py using argparse to get command line parameters for the main() function.</p>
  
  <pre><code>""" 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()
  </code></pre>
  
  <p>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. </p>
  
  <pre><code>""" bar.py """
  import sys
  import foo
  
  if __name__ == '__main__':
      sys.argv.append('-a')
      foo.main()
  </code></pre>