1、@pytest.fixture()默认参数
import fixture
@pytest.fixture()如果里面什么参数都不写,默认为@pytest.fixture(scope = "function")
2、@pytest.fixture(scope = "function")
如果@pytest.fixture(scope = "function")下面紧接着一个方法就是 夹具要执行的前置或者后置方法,此处参数没有写autouse="Ture",
所以如果想每个函数都执行此前置或者后置条件,需要在要执行此前置或者后置条件的函数中传入fixture夹具定义的方法名
import fixture
@pytest.fixture(scope = "function")
def functionOne():
print("前置条件")
def caseOne(functionOne):
print("测试")
3、如果@pytest.fixture(scope = "function",autouse="Ture")中有参数,如果执行某个文件,那么该文件中每次执行性一个函数前都会执行此前置条件
4、另外如果@pytest.fixture(scope = "function",autouse="Ture")的前置条件函数有return语句,其他函数要想或者此return值,也需要在函数入参中传入此前置函数才能获得此前置函数返回的return值
import fixture
@pytest.fixture(scope = "function")
def functionOne():
print("前置条件")
return 4
def caseOne(functionOne):
assert functionOne==1 #结果为Ture
浙公网安备 33010602011771号