框架简介:使用pytest库,去运行测试用例,用yaml做数据驱动,allure生成测试报告。
测试报告效果
项目目录结构
一、pytest.ini文件
pytest的配置文件,用来配置运行规则和运行命令。
addopts 为运行命令,命令之间用空格隔开.。-vs:表示显示详细调试信息;./temps 为allure测试报告生成目录 ;–clean 为清除历史报告。
testpaths 填写测试用例的目录。
python_files、python_classes、python_functions分别定义了文件名、类名、函数名的规则,只有满足规则才会被执行。
[pytest]
addopts = -vs --alluredir ./temps --clean-alluredir
testpaths = ./test_cases
python_files = test_*.py
python_classes = Test*
python_functions = test_*
二、封装基本接口请求方法
封装GET和POST请求,根据method去执行并返回res。
import requests
import json
class RequestMethod:
session = requests.session() # 会话
def all_send_request(self, method, url, data, headers, **kwargs):
method = str(method).lower()
if method == "get":
res = RequestMethod.session.request(method=method, url=url, params=data, **kwargs)
elif method == "post":
str_data = json.dumps(data