• pytest文档29-allure-pytest


    前言

    之前写了个pytest的allure相关的教程,只是停留在环境搭建完成,后续一直没用,小编一直不喜欢这种花里胡哨的报告。
    没办法,领导就喜欢这种,小伙伴们也喜欢,所以还是得把allure用起来,年底了,给领导一个漂亮的报告,也好加鸡腿
    之前用的是pytest-allure-adaptor插件,一年多前写的了,很古老了,跟不上时代了,不能吸引当代的小青年,这里用最新的allure-pytest,符合当代小青年的口味。

    allure-pytest 环境准备

    windows环境相关:

    python 3.6版本
    pytest 4.5.0版本
    allure-pytest 2.8.13 最新版

    使用pip安装pytest和allure-pytest,加上--index-url地址,下载会快一些

    pip install pytest4.5.0 --index-url https://pypi.douban.com/simple
    pip install allure-pytest2.8.13 --index-url https://pypi.douban.com/simple

    安装完成之后,打开一个你之前写的pytest脚本,看能不正常使用,如果报错:AttributeError: module 'allure' has no attribute 'severity_level'
    这个是之前 pytest-allure-adaptor 这个插件与 allure-pytest 不能共存,卸载掉 pytest-allure-adaptor

    pip uninstall pytest-allure-adaptor

    allure命令行工具

    allure是一个命令行工具,需要去github上下载最新版https://github.com/allure-framework/allure2/releases

    或是百度网盘下载:

    链接:https://pan.baidu.com/s/1X6r2i7pJJk2iiHMmXiHPjg 
    提取码:yuo5 

    请尽快下载,过期不候。

    下载完成之后,解压到本地电脑

    把bin目录添加到环境变量Path下(需要重启电脑才能生效)

    用例demo

    conftest.py内容

    import pytest
    
    
    @pytest.fixture(scope="session")
    def login():
        print("用例先登录")
    
    

    test_allure_demo.py内容

    import allure
    import pytest
    
    @allure.step("步骤1:点xxx")
    def step_1():
        print("111")
    
    @allure.step("步骤2:点xxx")
    def step_2():
        print("222")
    
    @allure.feature("编辑页面")
    class TestEditPage():
        '''编辑页面'''
    
        @allure.story("这是一个xxx的用例")
        def test_1(self, login):
            '''用例描述:先登录,再去执行xxx'''
            step_1()
            step_2()
            print("xxx")
    
    
        @allure.story("打开a页面")
        def test_2(self, login):
            '''用例描述:先登录,再去执行yyy'''
            print("yyy")
    

    运行用例

    cd到test_allure_demo.py所在的目录文件,命令行执行

    pytest --alluredir ./report/allure_raw

    D:softcodexuexipytest>pytest --alluredir ./report/allure_raw
    ============================= test session starts =============================
    platform win32 -- Python 3.6.0, pytest-4.5.0, py-1.5.4, pluggy-0.13.1
    rootdir: D:softcodexuexipytest
    plugins: allure-pytest-2.8.6, forked-0.2, html-1.19.0, metadata-1.7.0, repeat-0.7.0, xdist-1.23.2
    collected 9 items
    
    case	est_allure_demo.py ..                                              [ 22%]
    case	est_x.py ......                                                    [ 88%]
    case	est_y.py .                                                         [100%]
    
    ============================== 9 passed in 0.21s ==============================
    

    执行完成后,在当前目录下,report目录会生成一个allure_raw的原始文件,这个只是测试报告的原始文件,不能打开成html的报告

    打开html的报告需要启动allure服务,启动命令如下

    allure serve report/allure_raw

    启动服务,它会自动给个端口,直接用默认浏览器打开了(执行启动命令显示allure不是内部指令,说明配置环境变量后需要重启电脑才生效)

    D:softcodexuexipytest>allure serve report/allure_raw
    Generating report to temp directory...
    Report successfully generated to C:UsersdellAppDataLocalTemp6056757827461248074allure-report
    Starting web server...
    2019-12-08 00:41:09.921:INFO::main: Logging initialized @2228ms to org.eclipse.jetty.util.log.StdErrLog
    Server started at <http://192.168.1.125:35346/>. Press <Ctrl+C> to exit
    

    查看报告

    浏览器上打开的报告内容

    点 EN 按钮可以查看中文报告

    打开测试套件,可以查看报告的详情(可以用谷歌打开,自动翻译成中文),显示还是OK的

    以上内容从上海悠悠处转载:https://www.cnblogs.com/yoyoketang/p/12004145.html

  • 相关阅读:
    Servlet的建立以及配置使用
    maven 安装 及其 创建
    错误总结
    使用分层实现业务处理
    JSP数据交互(三)
    JSP数据交互(二)
    JSP数据交互(一)
    动态网页开发基础
    记录mysql编码问题
    .net core 2.0 升级 2.1 访问mysql出现bug解决
  • 原文地址:https://www.cnblogs.com/cavaXu/p/12781165.html
Copyright © 2020-2023  润新知