为什么用fixture
1.用例里有些需要执行某些步骤,有些不需要,而setup和teardown是针对整个脚本全局生效的
2.用fixture自定义前置条件,可以跨文件使用,即把@pytest.fixture()下定义的所有条件放置在一个文件中,不需要导入到test文件中,在测试用例执行时会自动寻找fixture
import pytest
@pytest.fixture()
def myfixture():
print("登陆操作")
class Test_demo():
def test_1(self, myfixture):
print("查看我的主页")
def test_2(self):
print("注册账户,不需要登陆的操作")