title: how to pass command line argument from pytest to code
body: <p>I am trying to pass arguments from a pytest testcase to a module being tested. For example, using the main.py from <a href="https://www.python-boilerplate.com/py3+argparse+pytest" rel="noreferrer">Python boilerplate</a>, I can run it from the command line as:</p>
  
  <pre><code>$ python3 main.py
  usage: main.py [-h] [-f] [-n NAME] [-v] [--version] arg
  main.py: error: the following arguments are required: arg
  $ python3 main.py xx
  hello world
  Namespace(arg='xx', flag=False, name=None, verbose=0)
  </code></pre>
  
  <p>Now I am trying to do the same with pytest, with the following test_sample.py</p>
  
  <p>(<strong>NOTE:</strong> the main.py requires command line arguments. But these arguments need to be hardcoded in a specific test, they should not be command line arguments to pytest. The pytest testcase only needs to send these values as command line arguments to main.main().)</p>
  
  <pre><code>import main
  def test_case01():
      main.main()
      # I dont know how to pass 'xx' to main.py,
      # so for now I just have one test with no arguments
  </code></pre>
  
  <p>and running the test as:</p>
  
  <pre><code>pytest -vs test_sample.py
  </code></pre>
  
  <p>This fails with error messages. I tried to look at other answers for a solution but could not use them. For example, <a href="https://stackoverflow.com/questions/42778124">42778124</a> suggests to create a separate file run.py which is not a desirable thing to do. And <a href="https://stackoverflow.com/questions/48359957">48359957</a> and <a href="https://stackoverflow.com/questions/40880259">40880259</a> seem to deal more with command line arguments for pytest, instead of passing command line arguments to the main code.</p>
  
  <p>I dont need the pytest to take command line arguments, the arguments can be hardcoded inside a specific test. But these arguments need to be passed as arguments to the main code. Can you give me a test_sample.py, that calls main.main() with some arguments?</p>