微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Pytest-allure测试报告

1. 下载安装

Allure 下载最新版本:https://github.com/allure-framework/allure2/releases

 

解压到非中文目录下

然后设置环境变量:

将allure/bin目录添加到path变量

重新打开cmd,运行allure --version

 

安装allure-pytest插件

pip install allure-pytest

2. 报告生成

创建项目或者包

创建脚本文件test-allure.py

修改运行方式为python运行

# -*- coding: utf-8 -*-

 

import pytest

import allure

import os

 

 

@pytest.fixture(scope='function')

def login():

    print("登录")

    yield

    print("登录完成")

 

 

def test_cart(login):

    """将手机加入购物车"""

    print("添加购物车1")

 

 

def test_cart1():

    """将电脑加入购物车"""

    print("添加购物车2")

 

 

if __name__ == "__main__":

    # 执行pytest单元测试,生成 Allure 报告需要的数据存在 /temp 目录

    pytest.main(['--alluredir', './temp'])

    # 执行命令 allure generate ./temp -o ./report --clean ,生成测试报告

    os.system('allure generate ./temp -o ./report --clean')

运行test-allure.py,会自动生成测试报告

 

 

 

打开测试报告

 

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐