在测试用例前加上
@pytest.mark.parametrize(“参数名”,列表数据)
参数名:用来接收每一项数据,并作为测试用例的参数。
列表数据:一组测试数据。
示例:
@pytest.mark.parametrize("account, password", [('abc', '123456')])
def test_login(self,account, password):
Course_Page.follow()
Login_Page.login(account,password)
方法二:
yaml文件存储数据
1、安装 pip inatall PyYaml
2、新建yaml文件
2、新建account.py 读取到yaml文件下的数据
import os import yaml cur_path = os.path.dirname(os.path.realpath(__file__)) configPath= os.path.join(cur_path,'account.yaml') file=open(configPath) # YAML 5.1版本后弃用了yaml.load(file)这个用法,需要指定Loader,通过默认加载器(FullLoader)禁止执行任意函数,该load函数也变得更加安全 temp=yaml.load(file,Loader=yaml.FullLoader) user1= temp['user']['user_id'] password1 = temp['user']['password']
3、在方法中调用account.py文件的参数
import pytest
from step.login import Login_Page
from data.account import *
class Test_Login:
def setup_class():
print("------->测试登录")
def test_login(self,account=user1, password=password1):
Login_Page.login(account,password)



