import pytest @pytest.fixture(scope="session") def my_setup(request): print ' Doing setup' def fin(): print (" Doing teardown") request.addfinalizer(fin)