python接口自动化之Yaml文件的读取

python接口自动化之Yaml文件的读取

python接口自动化之Yaml文件的读取代码如下:

import yaml
import json
def read_yaml(yaml_file_path):
    with open(yaml_file_path, encoding="utf-8") as f:
        value = yaml.load(stream=f, Loader=yaml.FullLoader)
        return value

yaml文件配置

-
	name: 查询校验
	request:
	 header:
	   Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjFhMDFjYmRjLTJkYmYtNGQzNS1hY2QyLTgyMjk2M2U4MDQxZCJ9.jRDZ-U7O6Ke5dvpOMzErODfz4sT0IkDCXYRjYrsWwoQyAUglD-zk6t1RE3ARrZXPV8BHq_hmrMXQXuk0xTYMPw
	   Content-Type: application/json;charset=UTF-8
	   Cookie: username=admin; rememberMe=true; password=F5VzlM2dUCE94Ojis1mtBUpNQtdhtt21lN1TKSEM8GiDSi3BtArp8PJ7ENoXVV6AUMnm8Ly+S7He+bBr1ilBCA==; Admin-Token=eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjFhMDFjYmRjLTJkYmYtNGQzNS1hY2QyLTgyMjk2M2U4MDQxZCJ9.jRDZ-U7O6Ke5dvpOMzErODfz4sT0IkDCXYRjYrsWwoQyAUglD-zk6t1RE3ARrZXPV8BHq_hmrMXQXuk0xTYMPw
	   User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Mobile Safari/537.36
	 url: http://127.0.0.1:8080/backend/garage/info
	 method: post
	 data:
	   pageNum : 1
	   pageSize: 10
	   garageStatus: ""
	   city: ""
	   createTime: ""
	   keyword: ""
	 extract: 查询成功

yaml文件读取

import pytest
from testdemo.read  import test_yaml
import json
nn=test_yaml(r'C:\Users\admin\Desktop\pytest-requests-new-yaml\testdemo\LOGIN.YAML')
class TestCase:
    @pytest.mark.parametrize('name',nn)
    def test_01(self, name):
       print(name['name'])

你可能感兴趣的:(python接口自动化,自动化,运维)