title: pytest multiple command-line skip options
body: <p>I have different suites of tests.</p>
  <p>There are normal tests, there are slow tests, and there are backend tests <strong>(and arbitrarily more &quot;special&quot; tests that may need to be skipped unless specified).</strong></p>
  <p>I would like to always skip slow and backend tests, unless <code>--run-slow</code> and/or <code>--run-backend</code> CLI options are passed.</p>
  <p>If only <code>--run-slow</code> is passed, I will run all normal tests <strong>plus</strong> &quot;slow&quot; tests (eg those tests marked <code>@pytest.mark.slow</code>). Same thing for <code>--run-backend</code>; and if both CLI options are passed then run all normal tests + slow tests + backend tests.</p>
  <p>I followed the pytest <a href="https://docs.pytest.org/en/stable/example/simple.html#control-skipping-of-tests-according-to-command-line-option" rel="nofollow noreferrer">Control skipping of tests according to command line option pattern</a> from the docs, but find myself not yet knowledgeable enough of pytest to extend it to having <em>multiple</em> skip CLI options.</p>
  <p>Can anyone help me out?</p>
  <p>Reference code snippet:</p>
  <pre class="lang-py prettyprint-override"><code>def pytest_addoption(parser):
      parser.addoption(&quot;--run-slow&quot;,    action=&quot;store_true&quot;, default=False, help=&quot;run slow tests&quot;)
      parser.addoption(&quot;--run-backend&quot;, action=&quot;store_true&quot;, default=False, help=&quot;run backend tests&quot;)
  
  
  def pytest_configure(config):
      config.addinivalue_line(&quot;markers&quot;, &quot;slow: mark test to run slow&quot;)
      config.addinivalue_line(&quot;markers&quot;, &quot;backend: mark test as backend&quot;)
  
  
  def pytest_collection_modifyitems(config, items):
      if config.getoption(&quot;--run-slow&quot;) or config.getoption(&quot;--run-backend&quot;): # &lt;-- this line logic is bad!
          return
      skip = pytest.mark.skip(reason=&quot;need '--run-*' option to run&quot;)
      for item in items:
          if &quot;slow&quot; in item.keywords or &quot;backend&quot; in item.keywords:
              item.add_marker(skip)
  </code></pre>
  <p>Thank you!</p>