zoukankan      html  css  js  c++  java
  • pytest学习系列_pytest-html插件之生成HTML测试报告

    一、前言

      在我们做自动化的时候,写好用例是一方面,还有比较重要的是执行结果需要可视化,pytest-html插件就提供了一个相对比较好的解决方案

    二、安装

      pipi install pytest-html

    三、使用方法

      1、代码示例

    #!/usr/bin/python3
    # -*- coding: UTF-8 -*-
    """
    @author:durant.zeng
    @Description:描述
    @file:test_rerun.py
    @time:2020/12/11
    """
    
    import requests
    
    def test_taobao1():
        url = "https://taobao.com"
        r = requests.post(url=url,timeout=0.30)
        print(r.elapsed.total_seconds())
    
    
    def test_taobao2():
        url = "https://taobao.com"
        r = requests.post(url=url,timeout=0.30)
        print(r.elapsed.total_seconds())
    
    
    
    def test_taobao3():
        url = "https://taobao.com"
        r = requests.post(url=url,timeout=0.09)
        print(r.elapsed.total_seconds())

      2、执行命令

      pytest --reruns 2 --html=report.html

      与失败重试参数结合起来

    (CloudStorage) D:learnIOTCloudStorageunit>pytest --reruns 2 --html=report.html
    Test session starts (platform: win32, Python 3.7.2, pytest 6.0.1, pytest-sugar 0.9.4)
    rootdir: D:learnIOTCloudStorageunit
    plugins: Faker-4.1.3, html-3.1.0, metadata-1.11.0, rerunfailures-9.1.1, sugar-0.9.4, tavern-1.11.1, allure-pytest-2.8.18, base-url-1.4.2, forked-1.3.0, xdis
    t-2.1.0
    collecting ... 
     test_rerun.py ✓                                                                                                                              33% ███▍
     test_rerun.py ✓✓                                                                                                                             67% ████
     test_rerun.py ✓✓RR✓                                                                                                                         100% ███
    ███████
    ==================================================================== warnings summary =====================================================================
    c:usersdurant.zeng.virtualenvscloudstoragelibsite-packagespykwalifycore.py:7
      c:usersdurant.zeng.virtualenvscloudstoragelibsite-packagespykwalifycore.py:7: DeprecationWarning: the imp module is deprecated in favour of import
    lib; see the module's documentation for alternative uses
        import imp
    
    -- Docs: https://docs.pytest.org/en/stable/warnings.html
    ----------------------------------------- generated html file: file://D:learnIOTCloudStorageunit
    eport.html ------------------------------------------
    
    Results (2.98s):
           6 passed
           2 rerun

      3、报告展示,在当前目录生成报告

       4、指定报告路径,比如是工程目录report

       pytest --html=./report/report.html

    知道、想到、做到、得到
  • 相关阅读:
    Merge Two Sorted Lists
    4Sum
    Letter Combinations of a Phone Number
    3Sum Closest
    3Sum
    Longest Common Prefix
    Roman to Integer
    Integer to Roman
    Container With Most Water
    Regular Expression Matching
  • 原文地址:https://www.cnblogs.com/Durant0420/p/14106341.html
Copyright © 2011-2022 走看看