orion_tvv orion_tvv - 1 year ago 304
Python Question

Pytest setup/teardown hooks for session

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

Answer Source

These hooks work well for me.

def pytest_sessionstart(session):

def pytest_sessionfinish(session, exitstatus):

But actually next fixture with session scope looks much pretty.

@fixture(autouse=True, scope='session')
def my_fixture():
    # setup_staff
    # teardown staff
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download