Closed
Description
I have the following example:
from pytest import fixture
@fixture(scope='module')
def fixture1():
print('Setup of fixture1')
yield 'fixture1'
print('Teardown of fixture1')
@fixture(scope='module')
def fixture2():
print('Setup of fixture2')
yield 'fixture2'
print('Teardown of fixture2')
def test_1(fixture1):
print('Running test with {}'.format(fixture1))
def test_2(fixture1, fixture2):
print('Running test with {} and {}'.format(fixture1, fixture2))
def test_3(fixture2):
print('Running test with {}'.format(fixture2))
When running with --setup-plan
, I get the following output (indicating extra teardown of fixture1 and 2):
test_fixture_lifetime.py
SETUP M fixture1
test_fixture_lifetime.py::test_1 (fixtures used: fixture1)
TEARDOWN M fixture1
SETUP M fixture1
SETUP M fixture2
test_fixture_lifetime.py::test_2 (fixtures used: fixture1, fixture2)
TEARDOWN M fixture2
SETUP M fixture2
test_fixture_lifetime.py::test_3 (fixtures used: fixture2)
TEARDOWN M fixture2
TEARDOWN M fixture1
When running with --setup-show
, the SETUP and TEARDOWN markers occur where my actual setup and teardown code executes:
test_fixture_lifetime.py Setup of fixture1
SETUP M fixture1
test_fixture_lifetime.py::test_1 (fixtures used: fixture1)Running test with fixture1
.Setup of fixture2
SETUP M fixture2
test_fixture_lifetime.py::test_2 (fixtures used: fixture1, fixture2)Running test with fixture1 and fixture2
.
test_fixture_lifetime.py::test_3 (fixtures used: fixture2)Running test with fixture2
.Teardown of fixture2
TEARDOWN M fixture2Teardown of fixture1
TEARDOWN M fixture1