title: Run method only if --collect-only was used
body: <p>I'm trying to collect some stats of how many test cases there are per feature or team, and want to do this only during collection, not when everyone in my company runs their tests. I'm looking for a way to run a function only if <code>--collect-only</code> was used in the <code>py.test</code> command.</p>
  
  <p><strong>Goal</strong>:</p>
  
  <ul>
  <li>Run some code only if <code>--collect-only</code> was used </li>
  <li>I need access to the
  test <code>items</code> data structure (i.e. I need all of the markers that were
  used)</li>
  </ul>
  
  <p>Currently, I am doing this via <code>pytest_collection_modifyitems</code> hook:</p>
  
  <pre><code>def pytest_collection_modifyitems(config, items):
      # This hook runs after collection
      for item in items:
          teams = [mark.name for mark in item.iter_markers() if mark.name.startswith('team_')]
          features = [mark.name for mark in item.iter_markers() if mark.name.startswith('feature_')]
  
          # do something with these markers
  </code></pre>
  
  <p>Is there a way to run this code above if and only if py.test was run with <code>--collect-only</code>? If anyone has suggestions on better ways to do this, please help!</p>
  
  <p>Thanks!</p>