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

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

 更新時間:2022年07月08日 08:49:28   作者:小旭2021  
這篇文章介紹了Pytest測試報(bào)告工具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 ===========================================================================

報(bào)告:

你還可以通過--allure-severities選項(xiàng)指定嚴(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 ===========================================================================

報(bào)告:

你也可以通過--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裝飾器來實(shí)現(xiàn)(固件同樣支持)。

該裝飾器會將方法或函數(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)題

如果你想讓測試標(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]

報(bào)告:

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

報(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> 測試頁面 </body>', 'Attach with HTML type', allure.attachment_type.HTML)

報(bào)告:

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

報(bào)告:

注意:

@allure.issue 將提供帶有小錯誤圖標(biāo)的鏈接,該描述符將測試用例ID作為輸入?yún)?shù),以將其與提供的問題鏈接類型的鏈接模板一起使用。
鏈接模板在 --allure-link-patternPytest 的配置選項(xiàng)中指定。鏈接模板和類型必須使用冒號指定:
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)文章

最新評論

缙云县| 昌平区| 从江县| 雷波县| 崇仁县| 营口市| 凤台县| 万全县| 钟山县| 绥芬河市| 横峰县| 龙口市| 温泉县| 德州市| 调兵山市| 祁东县| 邯郸县| 宜阳县| 阳泉市| 罗山县| 铜梁县| 斗六市| 来安县| 秭归县| 舞钢市| 永登县| 阿图什市| 河南省| 庆元县| 土默特左旗| 沙田区| 和顺县| 武定县| 井冈山市| 乡宁县| 郯城县| 中阳县| 靖西县| 革吉县| 枣庄市| 肥东县|