Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用pytest.fixture on setup_方法_Python_Python 3.x_Unit Testing_Pytest_Pytest Benchmark - Fatal编程技术网

Python 使用pytest.fixture on setup_方法

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

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


您可以将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'