zoukankan      html  css  js  c++  java
  • Pytest+Allure环境的搭建

    参考博客

    测试报告解释

    pytest+allurre进阶

    1. pytest的安装:

    1.1. windows下:

    pip install pytest
    

    1.2. linux下:

    pip install pytest
    

    2. 安装pytest-allure-adaptor插件

    2.1. windows下:

    pip install pytest-allure-adaptor
    

    3. allure的安装:

    3.1. windows下:

    前情提示: allure是基于Java的一个程序,需要Java1.8的环境,没有安装需要去安装一下。

    Windows下不能直接安装,点击此链接下载压缩包

    下载之后,将压缩包解压到一个磁盘中,我这里用的是F

     
    image

    3.2. 配置allure的环境变量

     
    image
     
    image

    点击确定,保存。这样就可以通过CMD使用allure命令

    3.3. 编写测试文件

    pycharm新建一个test_demo.py文件,代码如下:

    import allure
    
    
    @allure.MASTER_HELPER.feature("测试Dome")
    class TestDome(object):
    
        @allure.MASTER_HELPER.step("定义被测函数")
        def func(self, x):
            return x+1
    
        @allure.MASTER_HELPER.story("被测场景")
        @allure.MASTER_HELPER.severity("blocker")
        @allure.MASTER_HELPER.step("断言结果")
        def test_func(self):
            # with allure.MASTER_HELPER.step("断言结果"):
            allure.MASTER_HELPER.attach("预期结果", "{}".format(self.func(3)))
            allure.MASTER_HELPER.attach("实际结果", "{}".format(5))
            assert self.func(3) == 5
    
    

    3.4. 生成测试报告

    pycharm中打开terminal

     
    image

    输入命令pytest -s --alluredir=report,会遇到以下这个错误:

     
    image

    进入allure下面的utils文件,修改以下代码:

    # utils文件,可以通过from allure import utlis进入
    
    for suitable_name in suitable_names:
                # markers.append(item.get_marker(suitable_name))
                markers.append(item.get_closest_marker(suitable_name))
    
    
     
    image

    修改之后,再次运行pytest -s --alluredir=report命令:

     
    image

    运行后,无上述错误,同时会生成一个report文件。其中会有一个xml格式的报告:

     
    image
     
    image

    当然xml格式的报告不够直观,我们需要通过allure将它转成HTML格式的报告。通过cmd命令cdreport的根目录下,执行allure generate --clean report

     
    image

    回到根目录下,会生成一个allure-report的文件夹,在pycharm中打开文件夹,点击index.html运行

     
    image

    ok,到此为止。可以看到我们的精美的测试报告了

     
    image
     



    作者:努力学习的小白
    链接:https://www.jianshu.com/p/9673b2aeb0d3
    來源:简书
    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

  • 相关阅读:
    2021.1.28 个人rating赛补题报告
    2021.1.23 个人rating赛补题报告
    2021.1.23 个人rating赛补题报告
    2020.12.14 个人训练赛补题报告
    2020.11.28 2020团体程序设计天梯赛补题报告
    2020.12.3 Codeforces Beta Round #73(Div2)补题报告
    Xhorse VVDI Prog V5.0.6 is Ready for BCM2 Adapter
    Program 2021 Ford Bronco All Keys Lost using VVDI Key Tool Plus
    Xhorse VVDI Prog V5.0.4 Software Update in July 2021
    How to use Xhorse VVDI2 to Exchange BMW FEM/BDC Module?
  • 原文地址:https://www.cnblogs.com/wanghuaqiang/p/10125623.html
Copyright © 2011-2022 走看看