第一步:下载

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文件如下

  1. [pytest]
  2. # 这是配置文件
  3. addopts = vs ‐‐alluredir=reports/temps ‐‐cleanalluredir
  4. testpaths = testcases/
  5. python_files = test_*.py
  6. python_classes = Test*
  7. python_functions = test_*
  8. markers =
  9. smoke:冒烟测试
  10. productmanage:商品管理模块

加上—clean-alluredir表示:每执行一次把原来的清除。
2.all.py文件如下:

  1. if __name__ == '__main__':
  2. pytest.main()
  3. time.sleep(3)
  4. os.system("allure generate reports/temps ‐o reports/allures ‐‐clean")

加上—clean表示:每执行一次把原来的清除。

第四步:实现logo定制

1.修改E:\allure-2.13.7\config下的allure.yml配置文件,加入:自定义logo插件。最后一
句。

  1. plugins:
  2. junitxmlplugin
  3. xunitxmlplugin
  4. trxplugin
  5. behaviorsplugin
  6. packagesplugin
  7. screendiffplugin
  8. xctestplugin
  9. jiraplugin
  10. xrayplugin
  11. customlogoplugin

2.修改插件里面的图片和样式

  1. /*
  2. .side‐nav__brand {
  3. background: url('custom‐logo.svg') no‐repeat left center !important;
  4. margin‐left: 10px;
  5. }
  6. */
  7. .sidenav__brand{
  8. background: url('logo.png') norepeat left center !important;
  9. marginleft: 20px;
  10. height: 90px;
  11. backgroundsize: contain !important;
  12. }
  13. .sidenav__brandtext{
  14. display: none;
  15. }

第五步:生成报告

一、方式一
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