通过读取yaml文件获得多个参数

发布时间 2023-08-02 21:21:11作者: 胖豆芽
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