擅长:python、mysql、java
<p>我过去所做的是为这些测试创建自定义标记,这样我就可以使用运行测试的<code>-m</code>命令行标志排除它们。例如,在<code>pytest.ini</code>文件中放置以下内容:</p>
<pre><code>[pytest]
markers =
longrunning: marks a test as longrunning
</code></pre>
<p>然后我们只需要用这个标记来标记长期运行的测试</p>
<pre><code>@pytest.mark.longrunning
def test_my_long_test():
time.sleep(100000)
</code></pre>
<p>然后,当我们运行测试时,我们将执行<code>pytest -m "not longrunning" tests/</code>以排除它们,并<code>pytest tests</code>以按预期运行所有内容</p>