0
点赞
收藏
分享

微信扫一扫

python之pytest接口测试

1.pytest安装

pip 版本:pip-21.0.1
pytest安装:pip install pytest
pytest查看:pip show pytest 

2.pytest框架原则
.py文件:test_开头或者test结尾
测试类:必须以Test开头,且不能有init方法
测试方法:test
开头
断言:assert开头

3.allure报告搭建
下载allure包
设置包所在位置的path环境变量:windows DOS下设置环境变量path。

命令:set path=%path%;[allure所在的bin目录路径]
如:set path=%path%;F:\BaiduNetdiskDownload\allure-2.13.0\bin
安装'allure-pytest':pip install allure-pytest
安装是否安装成功:allure

4.pytest框架与allure结合实现接口自动化可视化报告
思路:

  • 获取excel中的用例数据
  • 引用模块代码
  • 引入pytest框架-封装测试类、测试方法、数据驱动的方式调用模块代码
  • 断言
  • 执行测试用例,生成报告所需的pytest文件
  • allure可视化报告

5.需求:用例表数据,取值预期结果和请求参数,实现登录测接口测试用例的自动化测试,用pytest结合allure生成报告。


from tools.excelControl import get_excel_data
from libs.login import Login
import pytest,os
class TestLogin():
@pytest.mark.parametrize('inBody,reqData',get_excel_data('登录模块','Login'))
def test_login(self,inBody,reqData):
    res=Login().login(inBody)
    assert res['msg']==reqData['msg']
if __name__ == '__main__':
    pytest.main(['test_login.py','--alluredir','../report/tmp'])
    os.system('allure serve ../report/tmp')
举报

相关推荐

0 条评论