pytest的allure

Allure是一款轻量级并且非常灵活的开源测试报告框架。 它支持绝大多数测试框架, 例如TestNG、Pytest、JUint等。它简单易用,易于集成。

 先配置allure

 验证是否配置成功:

 安装allure

pip install allure-pytest

 Allure常用的几个特性

@allure.feature # 用于描述被测试产品需求

@allure.story # 用于描述feature的用户场景,即测试需求

with allure.step(): # 用于描述测试步骤,将会输出到报告中

allure.attach # 用于向测试报告中输入一些附加的信息,通常是一些测试数据,截图等

 读取xml生成测试报告

开发的模块

class kf(object):
    def add(self,a,b):
        c = a+b
        return c
    def reduct(self,a,b):
        c = a - b
        return c

准备数据

<gen>
    <add>
        <add1>7</add1>
        <add2>2</add2>
        <add3>5</add3>
    </add>
    <reduct>
        <reduct1>10</reduct1>
        <reduct2>8</reduct2>
        <reduct3>2</reduct3>
    </reduct>
</gen>

 读取数据

from xml.dom import minidom
class Readxml():
    def read_xml(self,filename,onename,twoname):
        root =minidom.parse(filename)
        firstnode =root.getElementsByTagName(onename)[0]
        secondnode=firstnode.getElementsByTagName(twoname)[0].firstChild.data
        return secondnode
r = Readxml()
print(r.read_xml("../data/test.xml","add","add1"))

进行生成测试报告

相减成功失败的

import pytest,allure,os
from demo.kaifa import kf
from readata.duquxml import Readxml
r = Readxml()
k = kf()
jian1 = r.read_xml("../data/test.xml","reduct","reduct1")
jian2 = r.read_xml("../data/test.xml","reduct","reduct2")
jian3 = r.read_xml("../data/test.xml","reduct","reduct3")
reduct = k.reduct(int(jian1),int(jian2))
class Testclass():
    @allure.feature("相减功能")
    @allure.story("相减成功")
    def test_res(self):
        assert reduct == int(jian3)

    @allure.feature("相减功能")
    @allure.story("相减失败")
    def test_ress(self):
        ress = k.reduct(int(jian2),int(jian1))
        assert ress == int(jian3)


pytest.main(['--alluredir', 'report/result', 'testallure.py'])
split = 'allure ' + 'generate ' + './report/result ' + '-o ' + './report/html ' + '--clean'
os.system(split)

 

 相加成功失败

import pytest,allure,os
from demo.kaifa import kf
from readata.duquxml import Readxml
r = Readxml()
k = kf()
jia1 = r.read_xml("../data/test.xml","add","add1")
jia2 = r.read_xml("../data/test.xml","add","add2")
jia3 = r.read_xml("../data/test.xml","add","add3")
add = k.add(int(jia1),int(jia2))
class Testclass():
    @allure.feature("相加功能")
    @allure.story("相加成功")
    def test_res(self):
        assert add == int(jia3)

    @allure.feature("相加功能")
    @allure.story("相加失败")
    def test_ress(self):
        ress = k.add(int(jia3),int(jia1))
        assert ress == int(jia3)


pytest.main(['--alluredir', 'report/result', 'testallure.py'])
split = 'allure ' + 'generate ' + './report/result ' + '-o ' + './report/html ' + '--clean'
os.system(split)

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值