pytest图形化测试报告allure-pytest配置

这篇博客介绍了如何在Python环境下配置pytest与allure,包括allure-pytest的安装,allure命令行工具的下载与环境变量配置,以及测试用例的执行和生成测试报告的过程。遇到的问题如模块冲突也给出了解决方法。
摘要由CSDN通过智能技术生成

参考链接 https://www.cnblogs.com/yoyoketang/p/12004145.html

一、allure-pytest 环境准备
  1. windows环境相关:

python+pytest+allure-pytest

  1. 安装allure-pytest

pip install allure-pytest

  • 查看是否安装成功—>Successfully installed allure-pytest-2.8.6
二、allure命令行工具
  1. allure是命令行工具,需要到github上找到download到本地,解压,配置环境变量
    下载地址:

https://github.com/allure-framework/allure2/releases

  • 此电脑–>属性–>高级系统设置–>环境变量–>系统环境变量 path 将解压的allure到bin,
    添加到path
  1. 查看是否生效 -->allure --version 执行结果–>2.13.6
三、用例demo
  1. 找一份test_allure_assert.py文件
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import pytest

# 断言是写自动化测试基本最重要的一步,一个用例没有断言,就失去了自动化测试的意义了。什么是断言呢?
# 简单来讲就是实际结果和期望结果去对比,符合预期那就测试pass,不符合预期那就测试 failed

def f():
    return  3

# 异常信息
'''
def test_function():
    # assert f() == 3
    a = f()
    assert a % 2 == 0, "判断a为偶数, 当前a的值为:%s"%a
'''


# 异常断言--暂不
# 常用断言
'''
pytest里面断言实际上就是python里面的assert断言方法,常用的有以下几种
assert xx 判断xx为真
assert not xx 判断xx不为真
assert a in b 判断b包含a
assert a == b 判断a等于b
assert a != b 判断a不等于b
'''


def is_true(a):
    if a > 0:
        return True
    else:
        return False

def test_01():
    # 断言为真
    a = 5
    b = -1
    assert is_true(a)
    assert not is_true(b)
    print "test_01()"


def  test_02():
    # b in a
    a = "hello"
    b = "hello aaaa"
    assert a in b
    print "test_02()"

def test_03():
    # 相等
    a = "ttt"
    b = "ttt"
    assert a == b
    print "test_03()"

def test_04():
    # 不等
    a = "tt1"
    b = "tt2"
    assert a != b
    print "test_04()"

if __name__ == "__main__":
    pytest.main(["-s", "assert.py"])
  1. 运行用例
    cd 切换到文件所在的目录文件,命令执行

pytest --alluredir ./report/allure_raw

  • 插曲:
    a. [出现报错:(如果报错:AttributeError: module ‘allure’ has no attribute ‘severity_level’)
    原因:allure-pytest 和 pytest-allure-adaptor 不能同时存在,卸载pytest-allure-adaptor
    pip uninstall pytest-allure-adaptor]

    b. 执行完成后,\report\allure_raw 出现原始文件,不能打开成html文件

  1. 打开html的报告需要启动allure服务,启动命令如下

allure serve report/allure_raw

四、启动服务,直接默认浏览器打开
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值