zoukankan      html  css  js  c++  java
  • pytest + allure 生成测试报告

    pytest测试样例规则:
    测试文件以test_开头(以_test结尾也可以)
    测试类以Test开头,并且不能带有 init 方法
    测试函数以test_开头
    断言使用基本的assert即可


    ubuntu 安装allure
    sudo apt-add-repository ppa:qameta/allure
    sudo apt-get update
    sudo apt-get install allure


    mac安装allure:
    brew install allure


    源码安装参考地址:
    https://bintray.com/qameta/generic/allure2


    安装pytest以及allure包:
    pip3 install pytest
    #不使用这个pip3 install pytest-allure-adaptor,用下面那个
    pip3 install allure-pytest


    创建一个用例
    test_one.py:

    class TestClassOne(object):
    def test_one(self):
    x = "this"
    assert 't'in x
    def test_two(self):
    x = "hello"
    assert hasattr(x, 'check')
    
    class TestClassTwo(object):
    def test_one(self):
    x = "iphone"
    assert 'p'in x
    def test_two(self):
    x = "apple"
    assert hasattr(x, 'check')

    #执行所有用例文件
    pytest --alluredir=report
    allure generate report


    #执行指定用例文件
    pytest -s -q --alluredir=report test_one.py
    allure generate report


    覆盖生成报告
    #allure generate report --clean

    #生成到指定文件夹
    allure generate report -o html


    执行完testcase后,生成报告,模版在 allure-report 中,将index.html在服务器环境中打开。


    默认情况下,report目录中的json文件是累加的,不会清除,如果需要重新跑一遍用例,那么应该先清空report文件夹,再执行上面的命令,即可显示本次执行结果。

  • 相关阅读:
    机器学习
    Python
    sublime的推荐插件
    C语言编程
    将生成logo图片导入到Altium Designer中
    基于MDK的stm32实践过程中,debug的总结
    LCD12864使用总结
    c语言使用技巧
    LCD12864显示中文乱码
    在Keil中做stm32的软件仿真,查看输出PWM波形时,在逻辑分析仪中规定IO口signal,出现"unknow signal"
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11384574.html
Copyright © 2011-2022 走看看