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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With