程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

pytest+Allure生成测试报告

发布于2019-08-07 14:38     阅读(1279)     评论(0)     点赞(3)     收藏(2)


版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/DaxiaLeeSuper/article/details/90613459
  1. 首先安装pytest
pip install pytest
  • 1
  1. 安装pytest的allure插件
pip install pytest-allure-adaptor
  • 1
  1. 安装allure,因为allure依赖于java环境,所以必须先安装java环境并设置环境变量(自行百度就可以)。

  2. 去以下链接,下载一个包,解压后将bin路径设置到环境变量path中
    https://github.com/allure-framework/allure2/releases
    在这里插入图片描述
    path环境变量如下图所示,
    在这里插入图片描述
    这样就可以通过cmd中的allure命令来生成测试报告

  3. 我在测试过程中提示module ‘pytest’ has no attribute ‘allure’,以下这篇文章可以解决:
    https://www.cnblogs.com/lansan0701/p/10345142.html

  4. 装好以后,来写个demo

#coding=utf-8

import pytest
import allure

marketid = ['101','102']
testlist = ['1','test','test1']
testlist2 = ['test0','test2','test3']

#市场id对应也生成相同的数组

@pytest.fixture(scope='module',autouse=True)
@allure.feature('测试准备')
def prepare():
    print('这是测试准备哦')
    yield
    print('module 测试结束')

@allure.feature('期权强平测试')
class Test_module1:
    @allure.feature('期权市价委托强平')
    @pytest.mark.parametrize('str1',testlist)
    @pytest.mark.parametrize('str2',testlist2)
    def test1(self,str1,str2):
        """
            用例描述:期权强平市价委托
        """
        stradd = str1 + str2
        print('这是test1')
        assert 1 == 2

    @allure.feature('期权限价委托强平')
    def test2(self):
        with allure.step("调节持仓"):
            x = '1'
            allure.attach(x)
            print('这是test2')
        with allure.step('进行强平的操作'):
            print('DTE')

class Test_module2:`在这里插入代码片`
    def test3(self):
        with allure.step("调节持仓"):
            x = '1'
            allure.attach(x)
            print('这是test2')
        with allure.step('进行强平的操作'):
            print('DTE')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

我用的是pycharm,在pycharm的Terminal中输入命令:

pytest -s -q --alluredir report
  • 1

这时候生成的是一堆json文件,不方便查看,大概长这样:
在这里插入图片描述
需要用刚才安装的allure command-line工具生成html格式的测试报告,在cmd中输入:

allure generate --clean report
  • 1

来看一下生成的报告路径:
在这里插入图片描述
打开上面图那个html,看一眼呗:(如果要用chrome打开,则必须在pycharm右键使用chrome打开,如果直接打开文件的话会404,不清楚原因,不过直接用firefox浏览器打开文件可以正常显示)
在这里插入图片描述
在这里插入图片描述
allure的其他用法,可以去官网看它的document和examples:
http://allure.qatools.ru/

行吧,测试报告就先整成这样吧!

https://blog.csdn.net/DaxiaLeeSuper/article/details/94138029这篇文章中写了如何该脚本配置Jenkins执行,有兴趣可以看下。



所属网站分类: 技术文章 > 博客

作者:天青色等烟雨

链接:https://www.pythonheidong.com/blog/article/11368/e32ce8749c9ff7291769/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

3 0
收藏该文
已收藏

评论内容:(最多支持255个字符)