下面是fixture的两种用法:
1.fixture固件的自动调用
1)@pytest.fixture(scope='class',params=['name1','name2'],autouse=True)
def login(request):
print("用户登录")
print("退出登录")
2)类中的每个用例都会自动调用login
2.fixture固件的手动调用
1)@pytest.fixture(scope='function',autouse=False)
def login():
print("用户登录")
print("退出登录")
2)测试用例中手动调用
def test_001(self, login):
只有指定的如上述调用了fixture函数的测试用例才会生效