Pytest setup/teardown 会话挂钩
Pytest setup/teardown hooks for session
Pytest
has setup and teardowns
module, class, method
.
挂钩
我想在设置中创建我的自定义测试环境(在测试会话开始之前)并在所有测试完成后进行清理。
换句话说,我如何使用像 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
Pytest
has setup and teardowns
module, class, method
.
我想在设置中创建我的自定义测试环境(在测试会话开始之前)并在所有测试完成后进行清理。
换句话说,我如何使用像 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