1
Pytest
hassetup and teardowns
钩子为module, class, method
。Pytest设置/拆卸会话的钩子
我想在安装程序(开始测试会话之前)中创建自定义测试环境,并在所有测试完成后进行清理。 换句话说,我怎样才能使用像setup_session and teardown_session
这样的挂钩?
Pytest
hassetup and teardowns
钩子为module, class, method
。Pytest设置/拆卸会话的钩子
我想在安装程序(开始测试会话之前)中创建自定义测试环境,并在所有测试完成后进行清理。 换句话说,我怎样才能使用像setup_session and teardown_session
这样的挂钩?
这些钩子为我工作很好:
def pytest_sessionstart(session):
# setup_stuff
def pytest_sessionfinish(session, exitstatus):
# teardown_stuff
但实际上与会话范围下夹具看起来更漂亮:
@fixture(autouse=True, scope='session')
def my_fixture():
# setup_stuff
yield
# teardown_stuff
http://stackoverflow.com/questions/23667610/difference-between -setupclass-and-setup-in-python-unittest –
@AriGold。其实我不使用单元测试课。我正在编写使用pytest fixture的测试函数。我在链接中看到了setup_class/teardown_class用法的示例。但我正在寻找诸如setup_session/teardown_session之类的东西。 –