title: is it possible to write a pytest friendly .py that runs as a standalone?
body: <p>I have a script that can generate a bunch of pytest friendly tests (py script) based on a template defined by the user.  </p>
  
  <p>I'd like to embedded all tests and logic w/in this one generated script and have pytest run against it.  This includes receiving command line parameters and parse them appropriately.  In short, is it possible to do something like the following with pytest?</p>
  
  <pre><code>def test_1():
     # some tests
  
  def test_2():
     # some more tests
  </code></pre>
  
  <p>etc...</p>
  
  <pre><code>if __name__ == "__main__":
     # parse command line parameters and setup tests
     pytest.main()  # run pytest on this file
  </code></pre>