pytest简易教程汇总,详见:https://www.cnblogs.com/uncleyong/p/17982846
测试数据
case.json
[
{
"uname": "ren",
"pwd": "123"
},
{
"uname": "qzcsbj",
"pwd": "456"
}
]
parametrize从json获取数据
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : 韧
# @wx :ren168632201
# @Blog :https://www.cnblogs.com/uncleyong/
import pytest
import json
import os
# 获取项目路径
BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def read_data_from_json(file_path):
data = {}
with open(file_path, 'r', encoding="utf-8") as fp:
data = json.load(fp)
print(f"返回的参数:{data}")
return data
@pytest.mark.parametrize("param", read_data_from_json(BASE_PATH+"/data/case.json"))
def test_case(param):
print(f"uname={param['uname']}, pwd={param['pwd']}")
结果:
所有评论(0)