Python 使用pytest.fixture on setup_方法
是否可以在setup_方法上使用pytest.fixture,以便在每个测试用例之间始终完成一些操作?我试着使用下面的夹具,结构看起来还可以。我能够在funcA完成之前执行每个测试用例。但是,我不想包括``@pytest.mark.usefixtures('funcA')Python 使用pytest.fixture on setup_方法,python,python-3.x,unit-testing,pytest,pytest-benchmark,Python,Python 3.x,Unit Testing,Pytest,Pytest Benchmark,是否可以在setup_方法上使用pytest.fixture,以便在每个测试用例之间始终完成一些操作?我试着使用下面的夹具,结构看起来还可以。我能够在funcA完成之前执行每个测试用例。但是,我不想包括``@pytest.mark.usefixtures('funcA') 您可以将fixture作为参数传递给测试: def test_caseA(self, funcA): 'check a' def test_caseB(self, funcA): 'check b' def
您可以将fixture作为参数传递给测试:
def test_caseA(self, funcA):
'check a'
def test_caseB(self, funcA):
'check b'
def test_caseC(self, funcA):
'check c'
是的,但是我想知道我是否可以在setup_方法中使用它,因为funcA是在每个testcase之间执行的,我想你们不需要一个fixture。您可以在安装程序本身中对fixture执行任何操作。但my funcA实际上是一个从其他类继承的函数。所以我不想在setup_方法中复制代码,但只要使用它,无论您在fixture中做什么,您都应该能够在setup方法中执行相同的操作。
def test_caseA(self, funcA):
'check a'
def test_caseB(self, funcA):
'check b'
def test_caseC(self, funcA):
'check c'