自动化测试(四):pytest结合allure生成测试报告

Allure 报告框架的名称

allure: noun [ U ] 诱惑;魅力;吸引力

文章目录

  • [1. allure下载](#1. allure下载)
  • [2. pytest框架使用allure](#2. pytest框架使用allure)
  • [3. 生成allure报告](#3. 生成allure报告)

1. allure下载

下载前需要先安装JDK,这里可以参考自动化测试(二)
Allure下载路径https://github.com/allure-framework/allure2/releases

解压后放到指定文件夹,配置系统路径:

  1. win+R,control,系统与安全→系统→高级系统设置→环境变量→系统变量
  2. 选中Path,新建系统变量

    统统确认。
  3. 测试是否安装成功:cmd中allure --version,成功则显示版本型号。在pycharm的terminal中运行时记得配置完路径后重启一下pycharm使得环境生效,否则报错。

2. pytest框架使用allure

在pytest.ini中配置allure,比如下面的最下方配置 allure 报告

python 复制代码
[pytest]
# 设置测试文件的搜索路径
testpaths = ./test_Google_tran
# 设置测试文件的命名模式
python_files = test_*.py *_test.py
# 设置测试函数的命名模式
python_functions = test_*
# 设置测试类的命名模式
python_classes = Test*
# 设置测试日志的级别
log_cli = true
log_cli_level = INFO
log_file = test_log.txt
log_file_level = DEBUG

# 配置 allure 报告
addopts = -vs --alluredir=./allure-results  --clean-alluredir

此时执行后就会在对应的alluredir下生成:

3. 生成allure报告

方法一:使用os.system系统调用allure

run.py

python 复制代码
import os
import time

import pytest

if __name__ == "__main__":
    pytest.main(['--capture=sys'])
    time.sleep(3)  # 确保生成了allure临时文件
    os.system("allure generate ./allure-results -o ./reports --clean")

打开LearningAutoTesting\reports\index.html即可看到生成报告:

注意allure的图标是可以修改的,allure report+时间这一行文字也是可以修改的:
针对一次报告自定义窗口
针对所有报告修改窗口配置

相关推荐
努力搬砖的咸鱼1 天前
从零开始搭建 Pytest 测试框架(Python 3.8 + PyCharm 版)
python·pycharm·pytest
FINE!(正在努力!)3 天前
PyTest框架学习
学习·pytest
程序员杰哥4 天前
接口自动化测试之pytest 运行方式及前置后置封装
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
测试老哥4 天前
Pytest+Selenium UI自动化测试实战实例
自动化测试·软件测试·python·selenium·测试工具·ui·pytest
水银嘻嘻4 天前
07 APP 自动化- appium+pytest+allure框架封装
python·appium·自动化·pytest
天才测试猿5 天前
接口自动化测试之pytest接口关联框架封装
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
not coder6 天前
Pytest Fixture 详解
数据库·pytest
not coder6 天前
pytest 常见问题解答 (FAQ)
开发语言·python·pytest
程序员的世界你不懂6 天前
(1)pytest简介和环境准备
pytest
not coder6 天前
Pytest Fixture 是什么?
数据库·oracle·pytest