All是一款轻量级并且非常灵活的开源测试报告框架。它支持接大多数测试框架,例如TestNG,Pytest,JUint等。它简单易用,易用继承。
首先要安装allure
pip install allure-pytest
allure-pytest是Pytest的一个插件,通过它我们可以生成Allure所需要的用于生成测试报告的数据
在PyCharm中输入命令pip install pytest就可以导入pytest包啦
生成测试报告json
pytest.main(['--alluredir', 'report/result', 'testshop.py'])
运行前的代码
运行后的效果
将测试报告转为html格式
–html=…/report.html
运行前的效果
如果出现乱码
乱码解决办法
修改PyCharm配置:
File->Settings->Editor->File Encodings
把Global Encoding设置成GBK即可
解决办法
代码 将json转换成HTML文件
pytest.main([’–alluredir’, ‘report/result’, ‘testshop.py’])
# 将json转换成HTML文件
split = 'allure ’ + 'generate ’ + './report/result ’ + '-o ’ + './report/html ’ + ‘–clean’
os.system(split) # system函数可以将字符串转化成命令在服务器上运行
点击在网页中查看报告信息
把对应的测试用例都显示出来,展示出来的是print里面输出的
Allure装饰器
@allure.feature("")的使用,在feature里面添加要数据的描述标题
写一个有错误的测试用例,看看结果有什么不同
查看错误的测试用例结果
添加商品信息
Pytest和allure效果展示