Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest setup/teardown hooks for session

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?

like image 610
orion_tvv Avatar asked Nov 17 '16 17:11

orion_tvv


1 Answers

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
like image 197
orion_tvv Avatar answered Oct 05 '22 04:10

orion_tvv