Pytest
has setup and teardowns
hooks for module, class, method
.
I want to create my custom test environment in setup (before start of test session) and cleanup after all tests will be finished. In other words, how can I use hooks like setup_session and teardown_session
?
These hooks work well for me:
def pytest_sessionstart(session):
# setup_stuff
def pytest_sessionfinish(session, exitstatus):
# teardown_stuff
But actually next fixture with session scope looks much prettier:
@fixture(autouse=True, scope='session')
def my_fixture():
# setup_stuff
yield
# teardown_stuff
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.