在 setup_method 上使用 pytest.fixture

using pytest.fixture on setup_method

是否可以在 setup_method 上使用 pytest.fixture 以便在每个测试用例之间始终可以完成某些操作?我试过像下面这样使用夹具,结构看起来不错。我能够在 funcA 完成之前执行每个测试用例。但是,我不想包括``` @pytest.mark.usefixtures('funcA')


    class TestSuite(TestBase):
        @classmethod
        def setup_class(cls):
            super(TestSuite, cls).setup_class()
            'do something for setup class'

        @classmethod
        def teardown_class(cls):
            super(TestSuite, cls).teardown_class()
            'do something for teardown class'


        def setup_method(self):
            'do log in'
            'do a,b c for setup_method'

        @pytest.fixture(scope="function")
        def funcA(self):
            print('do function A')

        @pytest.mark.usefixtures('funcA')
        def test_caseA(self):
            'check a'

        @pytest.mark.usefixtures('funcA')
        def test_caseB(self):
            'check b'

        @pytest.mark.usefixtures('funcA')
        def test_caseC(self):
            'check c'

您可以将夹具作为参数传递给测试:

def test_caseA(self, funcA):
    'check a'

def test_caseB(self, funcA):
    'check b'

def test_caseC(self, funcA):
    'check c'