Вы можете сделать это sh с наследованием. Создайте базовый класс для всех тестов, после чего вы сможете решить, какие тесты вы хотите переопределить within_foo()
class BaseTest:
@pytest.fixture
def foo(self):
self.within_foo()
def within_foo(self):
pass
@pytest.mark.testing
class TestSomething(BaseTest):
def within_foo(self):
print('this should be printed when running test_foo')
def test_foo(self, foo):
pass
@pytest.mark.testing
class TestSomethingElse(BaseTest):
def test_foo_again(self, foo):
print('test_foo_again')
Outout
========================== 2 passed in 0.08 seconds ===========================
this should be printed when running test_foo
.test_foo
.test_foo_again