Section 1 Pytest 全局观
它可以和所有的自动化测试工具如selenium、appium、request、结合实现web自动化,app自动化以及接口自动化;
可以跳过用例以及失败的用例重跑;
结果allure生成美观的测试报告;
和Jenkins持续集成;
有很多强大的插件
pytest-html
:生成HTML测试报告;pytest.main([‘-vs’, ‘—html=./report.html’])pytest-xdist
:多线程运行;pytest-ordering
:改变测试用例的执行顺序;pytest-rerunfailures
:失败用例重跑;allure-pytest
:生成allure测试报告。
在实际的项目中,一般都会使用requrements.txt文件保存所有的插件名称,下载方式:**pip install -r requrement.txt**
请求
- request最核心的请求
requests.request("post/get/delet/put", url, params)
- request最核心的请求
返回数据的格式
- 返回字典格式的数据
print(rep.json())
- 返回字符串的数据
print(rep.text)
- 返回字节格式的数据
print(rep.content)
- 返回状态码
print(rep.status_code)
- 返回状态信息
print(rep.reason)
- 返回cookie信息
print(rep.cookies)
- 返回编码格式
print(rep.encoding)
- 返回响应头
print(rep.headers)
- 返回字典格式的数据