欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Pytest測(cè)試報(bào)告工具Allure的高級(jí)用法

 更新時(shí)間:2022年07月08日 08:49:28   作者:小旭2021  
這篇文章介紹了Pytest測(cè)試報(bào)告工具Allure的高級(jí)用法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

Allure除了具有Pytest基本狀態(tài)外,其他幾乎所有功能也都支持。

1、嚴(yán)重性

如果你想對(duì)測(cè)試用例進(jìn)行嚴(yán)重等級(jí)劃分,可以使用@allure.severity裝飾器,它可以應(yīng)用于函數(shù),方法或整個(gè)類。

它以allure.severity_level枚舉值作為參數(shù),分別為:BLOCKER(中斷),CRITICAL(嚴(yán)重),NORMAL(常規(guī)),MINOR(輕微),TRIVIAL(不重要)。

示例:

# test_sample.py
import allure


# 兩數(shù)相加
def add(x, y):
    return x + y

# 測(cè)試類
@allure.severity(allure.severity_level.TRIVIAL)
class TestAdd:

    @allure.severity(allure.severity_level.MINOR)
    def test_first(self):
        assert add(3, 4) == 7

    @allure.severity(allure.severity_level.NORMAL)
    def test_second(self):
        assert add(-3, 4) == 1

    @allure.severity(allure.severity_level.CRITICAL)
    def test_three(self):
        assert add(3, -4) == -1

    @allure.severity(allure.severity_level.BLOCKER)
    def test_four(self):
        assert add(-3, -4) == -7

運(yùn)行:

E:\workspace-py\Pytest>pytest test_sample.py --alluredir=report --clean-alluredir
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        

test_sample.py ....                                                                                                                                                [100%]

=========================================================================== 4 passed in 0.06s ===========================================================================

報(bào)告:

你還可以通過--allure-severities選項(xiàng)指定嚴(yán)重等級(jí)運(yùn)行,多個(gè)以逗號(hào)分隔。

E:\workspace-py\Pytest>pytest test_sample.py --allure-severities normal,critical
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        

test_sample.py ..                                                                                                                                                  [100%]

=========================================================================== 2 passed in 0.02s ===========================================================================

2、功能

如果你想對(duì)測(cè)試功能、測(cè)試場(chǎng)景進(jìn)行行為描述,可以分別使用裝飾器:@allure.feature@allure.story

示例:

# test_sample.py
import allure

# 兩數(shù)相加
def add(x, y):
    return x + y

@allure.feature('測(cè)試類')
class TestAdd:

    @allure.story('01測(cè)試兩個(gè)正數(shù)相加')
    def test_first(self):
        assert add(3, 4) == 7

    @allure.story('02測(cè)試負(fù)數(shù)正數(shù)相加')
    def test_second(self):
        assert add(-3, 4) == 1

    @allure.story('03測(cè)試正數(shù)負(fù)數(shù)相加')
    def test_three(self):
        assert add(3, -4) == -1

    @allure.story('04測(cè)試兩個(gè)負(fù)數(shù)相加')
    def test_four(self):
        assert add(-3, -4) == -7

運(yùn)行:

E:\workspace-py\Pytest>pytest test_sample.py --alluredir=report --clean-alluredir
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        

test_sample.py ....                                                                                                                                                [100%]

=========================================================================== 4 passed in 0.06s ===========================================================================

報(bào)告:

你也可以通過--allure-features--allure-stories選擇指定具體功能和故事運(yùn)行,多個(gè)以逗號(hào)分隔。

E:\workspace-py\Pytest>pytest test_sample.py --allure-stories 01測(cè)試兩個(gè)正數(shù)相加
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        

test_sample.py .                                                                                                                                                   [100%]

=========================================================================== 1 passed in 0.02s ===========================================================================

3、步驟

如果你想對(duì)每個(gè)測(cè)試調(diào)用進(jìn)行非常詳細(xì)的逐步說明,可以通過@allure.step裝飾器來實(shí)現(xiàn)(固件同樣支持)。

該裝飾器會(huì)將方法或函數(shù)的調(diào)用與提供的參數(shù)一起添加到報(bào)表中,并且可以包含一條描述行,該行支持位置和關(guān)鍵字參數(shù)。

示例:

# test_sample.py
import pytest
import allure

@allure.step('兩數(shù)相加:{0} + {y}')
def add(x, y):
    r = x + y
    print_res(r)
    return r

@allure.step
def print_res(r):
    print('計(jì)算結(jié)果:', r)

class TestLearning:
    data = [
        [3, 4, 7],
        [-3, 4, 1],
        [3, -4, -1],
        [-3, -4, -7],
    ]
    @pytest.mark.parametrize("data", data)
    def test_add(self, data):
        assert add(data[0], data[1]) == data[2]

報(bào)告:

4、標(biāo)題

如果你想讓測(cè)試標(biāo)題更具可讀性,可以使用@allure.title裝飾器,該裝飾器支持參數(shù)的占位符并支持動(dòng)態(tài)替換。

示例:

# test_sample.py
import pytest
import allure
def add(x, y):
    return x + y
class TestLearning:
    data = [
        [3, 4, 7],
        [-3, 4, 1],
        [3, -4, -1],
        [-3, -4, -7],
    ]
    @allure.title("測(cè)試用例-{data}")
    @pytest.mark.parametrize("data", data)
    def test_add(self, data):
        assert add(data[0], data[1]) == data[2]

報(bào)告:

5、描述

如果你想添加測(cè)試的詳細(xì)說明,可以通過添加測(cè)試方法描述信息,也可以使用裝飾器@allure.description@allure.description_html

示例:

# test_sample.py
import allure

# 被測(cè)功能
def add(x, y):
    return x + y

# 測(cè)試類
class TestLearning:

    @allure.description('測(cè)試正數(shù)相加')
    def test_first(self):
        assert add(3, 4) == 7

    @allure.description_html('<h1> 測(cè)試負(fù)數(shù)相加 </h1>')
    def test_second(self):
        """你也可以在這里添加用例的描述信息,但是會(huì)被allure裝飾器覆蓋"""
        assert add(-3, -4) == -7

報(bào)告:

6、附件

如果你想在報(bào)告中顯示不同類型的附件,可以通過以下兩種方式來實(shí)現(xiàn):
allure.attach(body, name, attachment_type, extension)
allure.attach.file(source, name, attachment_type, extension)

示例:

import allure

def test_multiple_attachments():
    allure.attach.file(r'C:\Users\Public\Pictures\Sample Pictures\Koala.jpg', attachment_type=allure.attachment_type.JPG)
    allure.attach('<head></head><body> 測(cè)試頁(yè)面 </body>', 'Attach with HTML type', allure.attachment_type.HTML)

報(bào)告:

7、鏈接

如果你想關(guān)聯(lián)缺陷追蹤系統(tǒng)或測(cè)試管理系統(tǒng),你可以使用裝飾器@allure.link@allure.issue、@allure.testcase。

示例:

import allure

@allure.link('http://www.baidu.com')
def test_with_named_link():
    pass

@allure.issue('101', '缺陷問題描述')
def test_with_issue_link():
    pass

@allure.testcase('http://this.testcase.com', '測(cè)試用例標(biāo)題')
def test_with_testcase_link():
    pass

報(bào)告:

注意:

@allure.issue 將提供帶有小錯(cuò)誤圖標(biāo)的鏈接,該描述符將測(cè)試用例ID作為輸入?yún)?shù),以將其與提供的問題鏈接類型的鏈接模板一起使用。
鏈接模板在 --allure-link-patternPytest 的配置選項(xiàng)中指定。鏈接模板和類型必須使用冒號(hào)指定:
pytest test_sample.py --alluredir=report --allure-link-pattern=issue:http://www.mytesttracker.com/issue/{}

官方文檔地址:https://docs.qameta.io/allure/

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python中創(chuàng)建表格詳細(xì)過程

    Python中創(chuàng)建表格詳細(xì)過程

    這篇文章主要介紹了Python中創(chuàng)建表格,在python中使用tabulate庫(kù)來創(chuàng)建表格,并針對(duì)輸出形式進(jìn)行不斷改進(jìn)來美化輸出效果,并給出了代碼示例。需要的小伙伴可以參考一下
    2022-02-02
  • python內(nèi)置數(shù)據(jù)類型之列表操作

    python內(nèi)置數(shù)據(jù)類型之列表操作

    數(shù)據(jù)類型是一種值的集合以及定義在這種值上的一組操作。這篇文章主要介紹了python內(nèi)置數(shù)據(jù)類型之列表的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-11-11
  • Python?selenium?get_cookies獲取cookie不全的解決方案

    Python?selenium?get_cookies獲取cookie不全的解決方案

    之前使用爬蟲時(shí)最讓我頭疼的就是cookie失效的問題了,下面這篇文章主要給大家介紹了關(guān)于Python?selenium?get_cookies獲取cookie不全的解決方案,需要的朋友可以參考下
    2022-10-10
  • Python條件語(yǔ)句與循環(huán)語(yǔ)句

    Python條件語(yǔ)句與循環(huán)語(yǔ)句

    這篇文章主要介紹了Python條件語(yǔ)句與循環(huán)語(yǔ)句,條件語(yǔ)句就是通過指定的表達(dá)式的運(yùn)行結(jié)果來判斷當(dāng)前是執(zhí)行還是跳過某些指定的語(yǔ)句塊,循環(huán)語(yǔ)句就是對(duì)某些語(yǔ)句的重復(fù)執(zhí)行,這個(gè)重復(fù)執(zhí)行是通過指定表達(dá)式來控制的,下面來看具體內(nèi)容及續(xù)航管案例吧,需要的朋友可以參考一下
    2021-11-11
  • Flask框架編寫文件下載接口過程講解

    Flask框架編寫文件下載接口過程講解

    這篇文章主要介紹了Flask框架編寫文件下載接口的過程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2023-01-01
  • Python字典底層實(shí)現(xiàn)原理詳解

    Python字典底層實(shí)現(xiàn)原理詳解

    今天小編就為大家分享一篇Python字典底層實(shí)現(xiàn)原理詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • python版本的仿windows計(jì)劃任務(wù)工具

    python版本的仿windows計(jì)劃任務(wù)工具

    這篇文章主要介紹了python版本的仿windows計(jì)劃任務(wù)工具,計(jì)劃任務(wù)工具根據(jù)自己設(shè)定的具體時(shí)間,頻率,命令等屬性來規(guī)定所要執(zhí)行的計(jì)劃,當(dāng)然功能不是很全大家可以補(bǔ)充
    2018-04-04
  • NumPy 數(shù)組使用大全

    NumPy 數(shù)組使用大全

    這篇文章主要介紹了NumPy 數(shù)組使用大全,在本教程中,你將學(xué)習(xí)如何在 NumPy 數(shù)組上以多種方式添加、刪除、排序和操作元素。 文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • python讀寫修改Excel之xlrd&xlwt&xlutils

    python讀寫修改Excel之xlrd&xlwt&xlutils

    這篇文章主要介紹了python讀寫修改Excel之xlrd&xlwt&xlutils,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • 解決TensorFlow訓(xùn)練內(nèi)存不斷增長(zhǎng),進(jìn)程被殺死問題

    解決TensorFlow訓(xùn)練內(nèi)存不斷增長(zhǎng),進(jìn)程被殺死問題

    今天小編就為大家分享一篇解決TensorFlow訓(xùn)練內(nèi)存不斷增長(zhǎng),進(jìn)程被殺死問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02

最新評(píng)論