parametrize实现多用户登录(●'◡'●)
1、在yaml文件中写入多个用户名和密码,注意要使用list形式
login: - [usernam,password] - [usernam,password] - [usernam,password] - [usernam,password] - [usernam,password]
2、读取yaml文件
1 data_road = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'config', 'data.yaml') 2 3 4 def read_data(): 5 f = open(data_road, encoding="utf-8") 6 data = yaml.safe_load(f) 7 return data 8 9 10 get_data = read_data()
3、编写测试用例
import pytest import requests from utils.read_data import get_data @pytest.mark.parametrize("username,password",get_data['login']) def test_spark_login(username,password): json_data = { 'phone': username, 'password': password } r = requests.post('http://xxxxxxxxxxxxxx/login', json=json_data) print(r.json())
标签:parametrize,多用户,yaml,python,usernam,json,path,password,data From: https://www.cnblogs.com/songfeigogogo/p/18467798