目錄
1、簡介
2、安裝
3、示例
4、報告結構
1、簡介
1、Allure 框架是一個靈活的輕量級多語言測驗報告工具,它不僅以簡潔的 web 報告形式展示了測驗內容,而且允許參與開發程序的每個人從日常測驗執行中提取最大限度的有用資訊,
2、從 dev/qa 的角度來看,Allure 報告縮短了常見缺陷的生命周期:測驗失敗可以分為 bug 和中斷的測驗,還可以配置日志、步驟、固定裝置、附件、計時、歷史記錄以及與 TMS 和 bug 跟蹤系統的集成,因此負責任的開發人員和測驗人員將掌握所有資訊,
3、從管理者的角度來看,Allure 提供了一個清晰的"大圖",說明了哪些特性已經被覆寫,缺陷聚集在哪里,執行時間表是什么樣子,以及許多其他方便的事情,Allure 的模塊化和可擴展性保證您始終能夠微調某些東西,以使 Allure 更適合您,
2、安裝
一、命令列安裝:
在命令列中運行以下命令進行安裝:
pip install allure-pytest
或者(使用國內的豆瓣源,資料會定期同步國外官網,速度快,)
pip install allure-pytest -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
二、配置環境變數(可選):
Allure 是一個命令列工具,可以下載后進行環境變數配置,
下載地址:
https://github.com/allure-framework/allure2/releases

1、將下載的檔案進行解壓,


2、配置環境變數
Windows:
(1)復制路徑如:D:\allure-2.13.6\bin
(2)環境變數-》path新增環境編輯-》添加D:\allure-2.13.6\bin -》保存
Mac:
(1)復制路徑如:/Users/wangmeng/Documents/allure-2.13.6
(2)命令列輸入sudo vi ~/.bash_profile
(3)添加內容,保存退出:
export ALLURE_HOME=/Users/wangmeng/Documents/allure-2.13.6
export PATH=$PATH:$ALLURE_HOME/bin
(4)命令列輸入(使環境變數生效)source ~/.bash_profile
3、示例
專案目錄結構:

根目錄下conftest.py檔案
腳本代碼:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公眾號:AllTests軟體測驗
"""
import pytest
@pytest.fixture(scope="session")
def login():
print("===登錄,回傳:name,token===")
name = "AllTests"
token = "123456qwe"
yield name, token
print("===退出===")
根目錄下test_case.py檔案
腳本代碼:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公眾號:AllTests軟體測驗
"""
import pytest
from time import sleep
@pytest.mark.parametrize("n", list(range(5)))
def test_get_info(login, n):
sleep(1)
name, token = login
print("===獲取用戶個人資訊===", n)
print(f"用戶名:{name}, token:{token}")
test_baidu包下的conftest.py檔案
腳本代碼:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公眾號:AllTests軟體測驗
"""
import pytest
@pytest.fixture(scope="module")
def open_baidu(login):
name, token = login
print(f"===用戶 {name} 打開baidu===")
test_baidu包下的test_case1.py檔案
腳本代碼:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公眾號:AllTests軟體測驗
"""
import pytest
from time import sleep
@pytest.mark.parametrize("n", list(range(5)))
def test_case1_1(open_baidu, n):
sleep(1)
print("===baidu 執行測驗用例test_case1_1===", n)
@pytest.mark.parametrize("n", list(range(5)))
def test_case1_2(open_baidu, n):
sleep(1)
print("===baidu 執行測驗用例test_case1_2===", n)
test_weibo檔案夾下的test_case2.py檔案
腳本代碼:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公眾號:AllTests軟體測驗
"""
import pytest
from time import sleep
@pytest.mark.parametrize("n", list(range(5)))
def test_case2_no_fixture(login, n):
sleep(1)
print("===weibo 沒有__init__測驗用例,執行測驗用例test_case2_no_fixture===", login)
test_douyin包下的conftest.py檔案
腳本代碼:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公眾號:AllTests軟體測驗
"""
import pytest
@pytest.fixture(scope="function")
def open_douyin(login):
name, token = login
print(f"===用戶 {name} 打開douyin===")
test_douyin包下的test_case3.py檔案
腳本代碼:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公眾號:AllTests軟體測驗
"""
import pytest
from time import sleep
@pytest.mark.parametrize("n", list(range(5)))
class TestDouyin:
def test_case3_1(self, open_douyin, n):
sleep(1)
print("===douyin 執行測驗用例test_case3_1===", n)
def test_case3_2(self, open_douyin, n):
sleep(1)
print("===douyin 執行測驗用例test_case3_2===", n)
執行命令:
添加引數 --alluredir 選項,并提供指向測驗結果的檔案夾路徑
如:
pytest -n auto --alluredir=allure
運行結果:
在指定的allure檔案夾下,生成一大堆.json和.txt檔案

要想查看測驗結果報告,需要再執行allure命令來生成測驗報告,
執行命令:
allure serve allure

之后自動打開默認瀏覽器顯示測驗報告,

4、報告結構
-
Overview:總覽,
-
Categories:類別,默認是分了 failed 和 error,凡是執行結果是其中一個的都會被歸到類里面,可以通過這里快捷查看哪些用例是 failed 和 error 的,
-
Suites:測驗套件,就是所有用例的層級關系,可以根據 package、module、類、方法來查找用例,
-
Graphs:測驗結果圖形化,包括用例執行結果的分布圖,優先級,耗時等,
-
Timeline:可以看到測驗用例精確的測驗時序(執行順序),包括執行時間,
-
Behaviors:行為驅動,根據 epic、feature、story 來分組測驗用例,
-
Packages:按照 package、module 來分組測驗用例,
報告可進行不同語言的切換(默認為英文)

查看Suites(函式級別的測驗用例)
包名-模塊名-測驗用例

查看Suites(類級別的測驗用例)
包名-模塊名-類名-測驗用例

查看測驗用例詳情
Parameters:如果用了 @pytest.mark.parametrize,可以看到傳了什么引數和對應的值,
Set up:呼叫 fixture 的前置操作,
Tear down:呼叫 fixture 的后置操作,
stdout:輸出的資訊,


轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/347097.html
標籤:其他
上一篇:Python測驗框架pytest(28)測驗報告Allure - 動態生成標題、動態生成功能、報告添加用例失敗截圖
