Pytest+Allure生成测试报告(简单版,内附脚本)

Pytest+Allure生成测试报告(简单版,内附脚本)

python脚本:

#!/usr/bin/env python 
# encoding: utf-8 
"""
@author: 九九的金金子
@file: test_feature_story.py
@time: 2021/2/1 15:06
"""
import pytest
import allure


@allure.feature("搜索模块")
class TestSeach:
    def test_case1(self):
        print("case1")

    def test_case2(self):
        print("case2")


@allure.feature("登录模块")
class Testlogin:
    @allure.story("登录成功")
    @allure.title("登录成功")
    def test_login_success(self):
        with allure.step("步骤1:打开应用"):
            print("打开应用")

        with allure.step("步骤2:进入登录页面"):
            print("登录页面")

        with allure.step("步骤3:输入用户名和密码"):
            print("输入用户名和密码")
        print("这是登录成功:测试用例,登录成功")
        pass

    @allure.story("登录失败")
    @allure.title("登录失败")
    def test_login_success_a(self):
        print("这是登录失败:测试用例,登录成功")
        pass

    @allure.story("登录失败")
    @allure.title("登录失败")
    def test_login_success_b(self):
        print("这是登录失败:测试用例,登录成功")
        assert 1 == 2, 'error: b is bigger'

脚本执行步骤

第一步:执行脚本

pytest test_feature_story.py --alluredir ./result2 --clean-alluredir
# 执行用例脚本,结果输出到当前文件夹result2,如果存在,清除之前执行的结果。

第二步:输出HTML文件

allure generate ./result2 -o report2 --clean
# 将result2的内容转化成HTML格式,存在report2文件夹里,如果存在,先清除。

第三步:绑定本地IP,方便其他人打开

allure open -h 100.119.xx.xx -p 8883 ./report2
# 将report2的结果,绑定在本机IP上,可以用IP地址访问

Allure生成测试报告

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/daxiangaifashi/article/details/113570913