第一步:下载
1.官网下载allure文件:https://github.com/allure-framework/allure2/releases
2.下载之后解压到非中文的目录
3.把bin路径配置到系统变量path中:E:\allure-2.13.7\bin (注意分号不要是中文的)
第二步:安装
安装allure报告:pip install allure-pytest
验证:allure —version
注意:可能需要重启pycharm。
第三步:配置
1.pytest.ini文件如下
[pytest]
# 这是配置文件
addopts = ‐vs ‐‐alluredir=reports/temps ‐‐clean‐alluredir
testpaths = testcases/
python_files = test_*.py
python_classes = Test*
python_functions = test_*
markers =
smoke:冒烟测试
productmanage:商品管理模块
加上—clean-alluredir表示:每执行一次把原来的清除。
2.all.py文件如下:
if __name__ == '__main__':
pytest.main()
time.sleep(3)
os.system("allure generate reports/temps ‐o reports/allures ‐‐clean")
加上—clean表示:每执行一次把原来的清除。
第四步:实现logo定制
1.修改E:\allure-2.13.7\config下的allure.yml配置文件,加入:自定义logo插件。最后一
句。
plugins:
‐ junit‐xml‐plugin
‐ xunit‐xml‐plugin
‐ trx‐plugin
‐ behaviors‐plugin
‐ packages‐plugin
‐ screen‐diff‐plugin
‐ xctest‐plugin
‐ jira‐plugin
‐ xray‐plugin
‐ custom‐logo‐plugin
2.修改插件里面的图片和样式
/*
.side‐nav__brand {
background: url('custom‐logo.svg') no‐repeat left center !important;
margin‐left: 10px;
}
*/
.side‐nav__brand{
background: url('logo.png') no‐repeat left center !important;
margin‐left: 20px;
height: 90px;
background‐size: contain !important;
}
.side‐nav__brand‐text{
display: none;
}
第五步:生成报告
一、方式一
1.生成json文件
pytest.ini配置文件中:addopts = -vs —alluredir=reports/temps —clean-alluredir
2.生成报告
终端:allure generate ./reports/temps -o ./reports/report —clean
3.打开报告
终端:allure open ./reports/report
二、方式二
1.生成json文件
pytest.ini配置文件中:addopts = -vs —alluredir=reports/temps —clean-alluredir
2.生成报告并打开(本地节点和端口号)
终端:allure serve ./reports/temps -p 9999
报告默认位置:C:\Users\用户名\AppData\Local\Temp