自动化测试(四):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+时间这一行文字也是可以修改的:
针对一次报告自定义窗口
针对所有报告修改窗口配置

相关推荐
2601_9623878219 小时前
web自动化测试实战教程【selenium/unittest/pytest】【共193课
selenium·pytest·devops·web自动化测试·unittest
weixin_4407305021 小时前
使用pytest中方法控制执行步骤(test_begin.py、test_end.py,@pytest.mark.run(order=1))
开发语言·python·pytest
2601_962297251 天前
Python、Pytest、Allure、Selenium和Jenkins实现自动化测试集成实例
python·selenium·jenkins·pytest·allure
2601_962077602 天前
从零搭建Python接口自动化测试框架:pytest+requests实战指南
python·pytest·接口自动化·requests·框架搭建
weixin_440730502 天前
pytest结合allure生成html测试报告(step、story、severity、screenshot)
前端·html·pytest·allure报告
拜托多多指教2 天前
【Pytest框架学习】分层架构
python·pytest
2601_962299882 天前
python脚本如何单元测试
python·单元测试·pytest·unittest·mock对象
Tizzy JJ3 天前
Python + pytest 接口自动化测试框架实战:从零搭建企业级项目骨架
开发语言·python·pytest
Tizzy JJ3 天前
接口自动化测试实战:如何围绕真实业务场景设计高质量用例
python·自动化·pytest
测试老哥4 天前
Pytest 之assert断言的使用
自动化测试·软件测试·python·测试工具·测试用例·pytest·接口测试