擅长:python、mysql、java
<p>目标:默认情况下跳过标记为<code>@pytest.mark.integration</code>的测试</p>
<p><strong>conftest.py</strong></p>
<pre><code>import pytest
# function executed right after test items collected but before test run
def pytest_collection_modifyitems(config, items):
if not config.getoption('-m'):
skip_me = pytest.mark.skip(reason="use `-m integration` to run this test")
for item in items:
if "integration" in item.keywords:
item.add_marker(skip_me)
</code></pre>
<p><strong>pytest.ini</strong></p>
<pre><code>[pytest]
markers =
integration: integration test that requires environment
</code></pre>
<p>现在,除非使用</p>
<pre><code>pytest -m integration
</code></pre>