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

Python Allure庫的使用示例教程

 更新時(shí)間:2023年12月22日 14:47:13   作者:奔向理想的星辰大海  
Python Allure庫是一個(gè)實(shí)用可靠的測(cè)試報(bào)告框架,它幾乎可以與Python的其他庫和框架無縫集成,利用Python Allure庫,可以輕松生成易于閱讀的測(cè)試報(bào)告,讓測(cè)試變得更加簡(jiǎn)單便捷,本文主要介紹Python Allure庫的使用,感興趣的朋友一起看看吧

Python Allure庫是一個(gè)開源的跨平臺(tái)的測(cè)試報(bào)告框架,用于生成漂亮、易于閱讀和易于理解的測(cè)試報(bào)告。它支持Python的標(biāo)準(zhǔn)TestRunner框架并且可以生成不同的報(bào)告格式,如HTML報(bào)告、json報(bào)告等。本文將圍繞著Python Allure庫來進(jìn)行講解,讓大家了解它的用途和主要功能。

一、安裝Python Allure庫

要使用Python Allure庫,需要在命令行中安裝Allure命令行工具。

brew install allure

安裝完Allure命令行工具后,可通過pip安裝Python Allure庫。

pip install allure-pytest

二、使用Python Allure庫

1.簡(jiǎn)單示例

import pytest
import allure
@allure.step("參數(shù)相加 : {0},{1}")
def add(x, y):
    return x + y
@pytest.mark.parametrize('x', [0, 1])
@pytest.mark.parametrize('y', [2, 3])
def test_add(x, y):
    with allure.step("步驟1:輸入兩個(gè)參數(shù)"):
        print("輸入?yún)?shù):x->{},y->{}".format(x, y))
    with allure.step("步驟2:調(diào)用相加方法"):
        result = add(x, y)
    with allure.step("步驟3:輸出結(jié)果"):
        print("輸出結(jié)果:{}".format(result))
if __name__ == '__main__':
    pytest.main(['-s', '-q', '--alluredir', './report/'])
import pytest
import allure
@allure.step("參數(shù)相加 : {0},{1}")
def add(x, y):
    return x + y
@pytest.mark.parametrize('x', [0, 1])
@pytest.mark.parametrize('y', [2, 3])
def test_add(x, y):
    with allure.step("步驟1:輸入兩個(gè)參數(shù)"):
        print("輸入?yún)?shù):x->{},y->{}".format(x, y))
    with allure.step("步驟2:調(diào)用相加方法"):
        result = add(x, y)
    with allure.step("步驟3:輸出結(jié)果"):
        print("輸出結(jié)果:{}".format(result))
if __name__ == '__main__':
    pytest.main(['-s', '-q', '--alluredir', './report/'])

在腳本中首先引入pytest和allure庫,然后使用@allure.step包裝每個(gè)測(cè)試步驟,使用@allure.parametrize注釋來測(cè)試方法的步驟,最后使用pytest.main運(yùn)行腳本,運(yùn)行結(jié)果將生成在“./report/”文件夾中。

2.定制化報(bào)告

Python Allure庫提供了多種注釋,來增加測(cè)試報(bào)告的可讀性,讓報(bào)告更加直觀。

使用@allure.feature注釋來制定測(cè)試特性:

@allure.feature("加法運(yùn)算測(cè)試")
def test_add():
    pass

使用@allure.story注釋來制定測(cè)試場(chǎng)景:

@allure.story("測(cè)試加法")
def test_add():
    pass

3.報(bào)告展示

在生成報(bào)告后,可以通過運(yùn)行命令在瀏覽器中查看報(bào)告。

allure serve 報(bào)告目錄

三、總結(jié)

Python Allure庫是一個(gè)實(shí)用可靠的測(cè)試報(bào)告框架,它幾乎可以與Python的其他庫和框架無縫集成。利用Python Allure庫,可以輕松生成易于閱讀的測(cè)試報(bào)告,讓測(cè)試變得更加簡(jiǎn)單便捷。

到此這篇關(guān)于Python Allure庫的使用的文章就介紹到這了,更多相關(guān)Python Allure庫使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論