python-pytest+allure生成测试报告

前言

最近在学习python接口自动化,每天抽一点时间把学习的内容总结一下,主要是为了加强记忆(脑子是个好东西,可惜我没有),有错漏的地方大家给指出来,欢迎一起学习交流~

allure是一个开源的测试报告框架,pytest+allure实现运行指定测试用例,运行完生成html测试报告。

安装allure

mac打开终端
brew install allure
安装完成,执行allure --version,显示版本号即安装成功

自定义测试报告

在原来测试用例test_wework.py上,增加@allure.XX()即可

from common.wework import Wework
import allure

#生成报告,查看报告
#运行测试用例:pytest test_wework.py --clean-alluredir --alluredir ./../report
#直接查看报告:allure serve ./../report
#生成报告:allure generate ./../report -o ./../html --clean

@allure.testcase("https://www.baidu.com/")
@allure.epic("通讯录")
@allure.feature("企业微信测试")
class TestWework:
    @allure.story("获取员ID列表")
    @allure.title("获取成员ID列表-输入为空")
    def test_post_list_id(self):
        print(Wework().test_post_list_id(""))

    @allure.story("手机号获取userid")
    @allure.title("手机号获取userid-输入正确手机号")
    @allure.severity(allure.severity_level.BLOCKER)
    def test_post_getuserid1(self):
        print(Wework().test_post_getuserid("13126966988"))

    @allure.story("手机号获取userid")
    @allure.description("这条用例是为了验证...巴拉巴拉...的场景")
    @allure.title("手机号获取userid-手机号为空")
    @allure.severity(allure.severity_level.NORMAL)
    def test_post_getuserid2(self):
        print(Wework().test_post_getuserid(""))

allure的装饰器有很多,详情见博客
https://blog.csdn.net/wenxiaoba/article/details/127295970

生成html

怎么生成测试报告呢?通过main.py实现

import os
import pytest

if __name__ == '__main__':
    pytest.main(["-s","./case/test_wework.py","--clean-alluredir","--alluredir","./temp"])
    os.system("allure generate ./temp -o ./report --clean")

pytest.main([“-s”,“-v”,“-x”])
等同于控制台输入:pytest -s -v -x

pytest.main([“-s”,“./case/test_wework.py”,“–clean-alluredir”,“–alluredir”,“./temp”])
等同于控制台输入:pytest -s ./case/test_wework.py --clean-alluredir --alluredir ./temp

os.system是将字符串转化为命令在服务器上运行。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值