title: pytest: run test from code, not from command line
body: <p>Is it possible to run tests from code using pytest? I did find <code>pytest.main</code>, but it's just a command line interface available from code. I would like to pass a test class / function from the code.</p>
  
  <p>In unittest it's possible this way:</p>
  
  <pre><code>from unittest import TestLoader, TestCase, TestResult
  
  
  class TestMy(TestCase):
      def test_silly(self):
          assert False
  
  runner = TestLoader()
  test_suite = runner.loadTestsFromTestCase(TestMy)
  test_result = TestResult()
  test_suite.run(test_result)
  print(test_result)
  </code></pre>