擅长:python、mysql、java
<blockquote>
<p>is it possible to share a global variable among all tests (which would contains e.g. a list of path to the cached objects) ?</p>
</blockquote>
<p>我不会走那条路。全局可变状态是最好避免的,特别是在测试中。</p>
<blockquote>
<p>is there a mechanism in py.test to call some command once all the tests are run (whether they succeed or not)?</p>
</blockquote>
<p>是,将自动使用的会话范围的fixture添加到项目级文件中<code>conftest.py</code>:</p>
<pre><code># conftest.py
import pytest
@pytest.yield_fixture(autouse=True, scope='session')
def test_suite_cleanup_thing():
# setup
yield
# teardown - put your command here
</code></pre>
<p>屈服之后的代码将在测试套件的末尾运行一次,无论通过与否。</p>