title: How do I set sys.argv so I can unit test it?
body: <p>I would like to set</p>
  
  <pre><code>sys.argv
  </code></pre>
  
  <p>so I can unit test passing in different combinations.  The following doesn't work:</p>
  
  <pre><code>#!/usr/bin/env python
  import argparse, sys
  def test_parse_args():
      global sys.argv
      sys.argv = ["prog", "-f", "/home/fenton/project/setup.py"]
      setup = get_setup_file()
      assert setup == "/home/fenton/project/setup.py"
  def get_setup_file():
      parser = argparse.ArgumentParser()
      parser.add_argument('-f')
      args = parser.parse_args()
      return args.file
  if __name__ == '__main__':
      test_parse_args()
  </code></pre>
  
  <p>Then running the file:</p>
  
  <pre><code>pscripts % ./test.py                                                                                           
    File "./test.py", line 4
      global sys.argv
                ^
  SyntaxError: invalid syntax
  pscripts %  
  </code></pre>