一:使用pytest命令生成测试简单测试报告
pytest --html .\reports\result.html
命令生成简单测试报告
ps:需安装 --html pip install pytest-html
效果如下:
二、结合allure-pytest生成较为美观的报告
1.安装allure-pytest插件
2.下载allure,下载之后解压,然后配置环境变量(bin目录配置到系统变量的path路径)
下载地址:https://github.com/allure-framework/allure2/releases
3.验证allure是否安装成功:
1)win+r验证allure --version
,出现版本号则安装成功
2)pycharm验证(须重启pycharm,否则配置的环境变量未在pycharm中生效):
4.生成allure报告
a:生成临时JSON报告
在pytest.ini中配置临时文件存放路径--alluredir=./temps
,--clean-alluredir
每次执行清空上一次的文件
[pytest]
addopts = -vs --alluredir=./temps --clean-alluredir
testpath=./testcase
python_files=test_*.py
b.生成正式allure报告
import os
import pytest
import time
if __name__=='__main__':
pytest.main()
time.sleep(3)
os.system("allure generate ./temps -o ./report --clean")
当看到Report successfully generated to .\report日志则代表报告生成成功,使用浏览器打开查看