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)文章
Python3中的tuple函數(shù)知識(shí)點(diǎn)講解
在本篇文章里小編給大家整理了一篇關(guān)于Python3中的tuple函數(shù)知識(shí)點(diǎn)講解內(nèi)容,有興趣的朋友們可以學(xué)習(xí)參考下。2021-01-01python爬取網(wǎng)站數(shù)據(jù)保存使用的方法
這篇文章主要介紹了使用Python從網(wǎng)上爬取特定屬性數(shù)據(jù)保存的方法,其中解決了編碼問題和如何使用正則匹配數(shù)據(jù)的方法,詳情看下文2013-11-11使用pyqt 實(shí)現(xiàn)重復(fù)打開多個(gè)相同界面
今天小編就為大家分享一篇使用pyqt 實(shí)現(xiàn)重復(fù)打開多個(gè)相同界面,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-12-12在Python的Django框架中simple-todo工具的簡(jiǎn)單使用
這篇文章主要介紹了在Python的Django框架中simple-todo工具的簡(jiǎn)單使用,該工具基于原web.py中的開源項(xiàng)目,需要的朋友可以參考下2015-05-05python 實(shí)現(xiàn)讀取一個(gè)excel多個(gè)sheet表并合并的方法
今天小編就為大家分享一篇python 實(shí)現(xiàn)讀取一個(gè)excel多個(gè)sheet表并合并的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-02-02python實(shí)現(xiàn)反轉(zhuǎn)部分單向鏈表
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)反轉(zhuǎn)部分單向鏈表,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-09-09