import pytest import requests from utils.read_yaml import get_yaml_data # 多个参数(’class1,class2‘,[('age','eat'),('age','eat')]) @pytest.mark.parametrize('title,body,userId',[get_yaml_data()['list_test']]) def test_params(title,body,userId): HOST = 'ip' URL = '/posts/' url = HOST + URL json = { "title": title, "body": body, "userId": userId } res = requests.post(url, json=json) print(res.text) print(res.status_code) assert res.status_code==201
import yaml def get_yaml_data(): with open('../configs/params.yaml') as fo: return yaml.safe_load(fo)
name: - fqs - doudou # name:[fqs,doudou] animal: dog: age: 3 eat: meat cat: age: 2 eat: fish # animal:{dog:{age:3,eat:meat}{cat:{age:2,eat:fish}}} key: - value1 value2 value3 # key:[value1,value2,value3] json_test: title: foo body: bar userId: 1 list_test: - foo - bar - 1