最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Pytest測試報告工具Allure的高級用法

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

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

1、嚴(yán)重性

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

它以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

# 測試類
@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 ===========================================================================

報告:

你還可以通過--allure-severities選項指定嚴(yán)重等級運(yùn)行,多個以逗號分隔。

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、功能

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

示例:

# test_sample.py
import allure

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

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

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

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

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

    @allure.story('04測試兩個負(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 ===========================================================================

報告:

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

E:\workspace-py\Pytest>pytest test_sample.py --allure-stories 01測試兩個正數(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、步驟

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

該裝飾器會將方法或函數(shù)的調(diào)用與提供的參數(shù)一起添加到報表中,并且可以包含一條描述行,該行支持位置和關(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('計算結(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]

報告:

4、標(biāo)題

如果你想讓測試標(biāo)題更具可讀性,可以使用@allure.title裝飾器,該裝飾器支持參數(shù)的占位符并支持動態(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("測試用例-{data}")
    @pytest.mark.parametrize("data", data)
    def test_add(self, data):
        assert add(data[0], data[1]) == data[2]

報告:

5、描述

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

示例:

# test_sample.py
import allure

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

# 測試類
class TestLearning:

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

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

報告:

6、附件

如果你想在報告中顯示不同類型的附件,可以通過以下兩種方式來實現(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> 測試頁面 </body>', 'Attach with HTML type', allure.attachment_type.HTML)

報告:

7、鏈接

如果你想關(guān)聯(lián)缺陷追蹤系統(tǒng)或測試管理系統(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', '測試用例標(biāo)題')
def test_with_testcase_link():
    pass

報告:

注意:

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

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

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

相關(guān)文章

  • Python執(zhí)行時間的計算方法小結(jié)

    Python執(zhí)行時間的計算方法小結(jié)

    這篇文章主要介紹了Python執(zhí)行時間的計算方法小結(jié)的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • 一行代碼解決動態(tài)執(zhí)行Python函數(shù)方法實例

    一行代碼解決動態(tài)執(zhí)行Python函數(shù)方法實例

    這篇文章主要為大家介紹了如何用一行代碼解決動態(tài)執(zhí)行Python函數(shù)方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12
  • python tkinter制作用戶登錄界面的簡單實現(xiàn)

    python tkinter制作用戶登錄界面的簡單實現(xiàn)

    這篇文章主要介紹了python tkinter制作用戶登錄界面的簡單實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • python實現(xiàn)數(shù)據(jù)導(dǎo)出到excel的示例--普通格式

    python實現(xiàn)數(shù)據(jù)導(dǎo)出到excel的示例--普通格式

    今天小編就為大家分享一篇python實現(xiàn)數(shù)據(jù)導(dǎo)出到excel的示例--普通格式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • Matplotlib實戰(zhàn)之柱狀圖繪制詳解

    Matplotlib實戰(zhàn)之柱狀圖繪制詳解

    柱狀圖,是一種使用矩形條,對不同類別進(jìn)行數(shù)值比較的統(tǒng)計圖表,這篇文章主要為大家詳細(xì)介紹了如何使用Matplotlib繪制柱狀圖,需要的可以參考下
    2023-08-08
  • NumPy數(shù)組復(fù)制與視圖詳解

    NumPy數(shù)組復(fù)制與視圖詳解

    NumPy 數(shù)組的復(fù)制和視圖是兩種不同的方式來創(chuàng)建新數(shù)組,它們之間存在著重要的區(qū)別,本文將給大家詳細(xì)介紹一下NumPy數(shù)組復(fù)制與視圖,并通過代碼示例講解的非常詳細(xì),需要的朋友可以參考下
    2024-05-05
  • python中with用法講解

    python中with用法講解

    在本篇文章里小編給大家整理的是關(guān)于python中with用法講解內(nèi)容,有需要的朋友們可以參考下。
    2020-02-02
  • 節(jié)日快樂! Python畫一棵圣誕樹送給你

    節(jié)日快樂! Python畫一棵圣誕樹送給你

    節(jié)日快樂!這篇文章主要介紹了如何使用Python畫一棵圣誕樹,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • Python??序列化反序列化和異常處理的問題小結(jié)

    Python??序列化反序列化和異常處理的問題小結(jié)

    這篇文章主要介紹了Python?序列化反序列化和異常處理,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-12-12
  • 關(guān)于torch.scatter與torch_scatter庫的使用整理

    關(guān)于torch.scatter與torch_scatter庫的使用整理

    這篇文章主要介紹了關(guān)于torch.scatter與torch_scatter庫的使用整理,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09

最新評論

志丹县| 洛南县| 聂荣县| 衡东县| 达拉特旗| 泰安市| 靖安县| 丰县| 彰化县| 海盐县| 临沭县| 安溪县| 合阳县| 罗田县| 定州市| 胶南市| 乌鲁木齐县| 吉木乃县| 桐城市| 浪卡子县| 含山县| 磐安县| 剑川县| 子长县| 新津县| 温宿县| 出国| 婺源县| 湘潭市| 宁明县| 资阳市| 雅安市| 岱山县| 融水| 鹤庆县| 额尔古纳市| 永春县| 蒙山县| 肇源县| 普安县| 金湖县|