栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pytest的allure

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

准备数据:


   
        7
        2
        5
   
   
        10
        8
        2
   

 读取数据:

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)
  

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/313321.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号