zoukankan      html  css  js  c++  java
  • pytest+allure自动化测试框架(一)

     

    pytest是Python最流程的单测框架之一。

    在本文中,我们将会介绍pytest的特点,功能和使用。

    Demo

    安装Python依赖库:
    pip3 install pytest
    pip3 install pytest-allure-adapto

    文件目录:

    三个pytest测试脚本(注:一定要以test_或xx_test格式,函数名称最好也参照)

    @pytest.mark.parametrize 函数装饰器传参用的
    @pytest.mark.parametrize("a,b,expected", testdata)
    def test_timedistance_v0(a, b, expected):
        diff = a - b
        assert diff == expected
    
    
    @pytest.mark.parametrize("a,b,expected", testdata, ids=["forward", "backward"])
    def test_timedistance_v1(a, b, expected):
        diff = a - b
        print(diff)
        assert diff == expected
    @pytest.mark.parametrize("a,b,c", testdata1,ids=['1'])
    def test_from(a,b,c):
        test_f=a+b
        assert test_f==c
    @pytest.mark.parametrize("test_input,expected",[("3+5",8),("3+9",12),("3*5",8),])
    def test_evel(test_input,expected):
        assert  eval(test_input)==expected
    if __name__ == '__main__':

    pytest.main(['-s', '-q', '--alluredir', './report/html']) #执行改目录下的所有测试脚本且生成测试报告,生成报告肯定是非易懂的所以后面用到allure
    test()

     在项目目录dos执行这个命令也可以生成测试报告

    pytest -s -q --alluredir report====代码里'-s', '-q', '--alluredir', './report/html'

    allure部分

    首先要安装allure

    pip install pytest-allure-adaptor

    allure-commandline下载链接

    https://github.com/allure-framework/allure1/releases/download/allure-core-1.5.2/allure-commandline.zip

    主要找两个目录:首先进入allure的bin目录下执行

    在dos目录进入bin目录下执行(我没有设置环境变量,时间充足的童鞋或者常用的童鞋建议path下加上bin目录的环境变量)

    allure generate report/ -o report/html
    allure generate【reprot目录】-0 【report目录下加上html目录】

     E:untitled3 est eport -o E:untitled3 est eporthtml(这个是我的见笑~~)

    执行后发现生成生成 Report文件的html文件里在使用pycharm打开可以看到生成的易懂的测试报告

    (到这里pytest编写了测试脚本,allure展示了完美的测试结果报告,但是小编也是一名新生发现变更pytest代码后allure没有自动更新测试报告
    比如:我之前写了10条case后来接口改造,需要做关联变成15条case但是打开测试报告后仍旧是之前10条,无奈之下小编写了一个test_api
    方法,主要用来重新生成报告,自动在dos里面重新执行E:untitled3 est eport -o E:untitled3 est eporthtml这条命令。
    有解决的方案的童鞋和大神请下方评论赐教

    可以生成pytest自己的hmtl报告 不加路径是该目录下所有测试脚本的html报告,但是小编认为不够allure完美(给领导看这个可能会大概被骂吧)








    精彩文章:https://www.cnblogs.com/yrxns/p/8386267.html
         https://www.cnblogs.com/xiaoxi-3-/p/9492534.html
         http://www.cnblogs.com/Raul2018/p/9469323.html

     
    
    
    
  • 相关阅读:
    使用VC++生成调试信息
    在Xp home上安装Rose 2003
    SkyDrive注册方法
    vsftpd同时使用系统用户和虚拟用户验证
    如何查看linux系统版本
    在RedHat AS中安装SVN
    Vnc & Gdm
    (转)如何:在设备上安装 SQL Server Compact 3.5
    java培训学习笔记一
    因为此版本的应用程序不支持其项目类型(.csproj),若要打开它,请使用支持此类型项
  • 原文地址:https://www.cnblogs.com/yingfei/p/10040174.html
Copyright © 2011-2022 走看看