import pytest
def read_yaml():
return ['成龙','张三','李四']
# ids 为参数取 别名
@pytest.fixture(scope="function", autouse=False, params=read_yaml(),ids=['a','b','c']) # 调用read_yaml,传参
def exec_db_sql(request): # request 固定参数
print("执行SQL...")
yield request.param # 取出参数
print("关闭数据库")
class Test_Run1():
def test1(self):
print("测试1.....")
def test2(self,exec_db_sql): # 调用
print("测试2..... " + exec_db_sql) # 打印参数
def test3(self):
print("测试3.....")
print("--------------------------------")
@pytest.mark.usefixtures("exec_db_sql") # 手动指定,类前后调用exec_db_sql
class Test_Run2():
def test_01(self):
print("测试1.....")
def test_02(self):
print("测试2.....")
def test_03(self):
print("测试3.....")