Having a testclass and testcases like below:
class TestSomething():
...
@pytest.fixture(autouse=True)
def before_and_after_testcases(self):
setup()
yield
cleanup()
def test_abc_1():
...
def test_abc_2():
...
def test_def_1():
...
def test_def_2():
...
Problem is, before_and_after_testcases()
would run for each testcase in the test class. Is it possible to let the fixture apply to testcases with abc
pattern in the function name only? The fixture is not supposed to run on test_def_xxx
, but I don't know how to exclude those testcases.
autouse=True
and then use@pytest.mark.usefixtures('before_and_after_testcases')
to decorate those functions -- or split it into two classes are my suggestions – Anthony Sottile