title: How can I write the pytest.main messages into a string?
body: <p>When I call pytest.main(...) in Python, it will display the unit test messages in the output window, such as </p>
  
  <pre><code>============================= test session starts =============================
  platform win32 -- Python 3.6.4, pytest-3.3.2, py-1.5.2, pluggy-0.6.0
  rootdir: xxx, inifile: pytest.ini
  plugins: cov-2.5.1, hypothesis-3.38.5
  collected 1 item
  
  ..\test_example.py F                                      [100%]
  
  ================================== FAILURES ===================================
  _______________________________ test_something ________________________________
  
      def test_something():
  &gt;       assert 1 == 0
  E       assert 1 == 0
  
  ..\test_example.py:5: AssertionError
  ========================== 1 failed in 0.60 seconds ===========================
  </code></pre>
  
  <p>My question is simply that how can I get the message above into a string object. The documentation doesn't say anything about this. And the what pytest.main() returns is only an integer that represents the error code. </p>
  
  <p><a href="https://docs.pytest.org/en/latest/usage.html#calling-pytest-from-python-code" rel="nofollow noreferrer">https://docs.pytest.org/en/latest/usage.html#calling-pytest-from-python-code</a></p>