title: pytest: How to get a list of all failed tests at the end of the session? (and while using xdist)
body: <p>I would like to have a <strong>list of all the tests that have failed</strong> to be used <strong>at the end of session</strong>.</p>
  
  <p>Pytest lets you define a hook <code>pytest_sessionfinish(session, exitstatus)</code>, that is called at the end of the session, where I wish to have that list. </p>
  
  <p><code>session</code> is a <code>_pytest.main.Session</code> instance that has the attribute <code>items</code> (type <code>list</code>), but I couldn't find whether the each <code>item</code> in that list passed of failed.</p>
  
  <ol>
  <li>How can a list of all failed tests could be retrieved at the end of the session?</li>
  <li><p>How can it be done while using <code>pytest-xdist</code> plugin, where I would like to get that list in the master process. Using this plugin, <code>session</code> does not even have <code>items</code> attribute in the master:</p>
  
  <pre class="lang-py prettyprint-override"><code>def pytest_sessionfinish(session, exitstatus):
      if os.environ.get("PYTEST_XDIST_WORKER", "master") == "master":
           print(hasattr(session, "items"))  # False
  </code></pre>
  
  </li>
  </ol>