allure(三十)--allure描述用例詳細講解


前言

pytest+allure是最完美的結合了,關於allure的使用,本篇做了一個總結。

allure報告可以包含很多詳細的信息描述測試用例,包括epic、feature、story、title、issue、testcase、severity等

allure用例描述

 

 測試案例

pytest結合allure測試用例

#test_a.py
import pytest
import allure
@pytest.fixture(scope="session")
def login():
    print("前置條件:登錄")

@allure.step("步驟1")
def step_1():
    print("操作步驟----1")

@allure.step("步驟2")
def step_2():
    print("操作步驟----2")

@allure.step("步驟3")
def step_3():
    print("操作步驟----3")

@allure.epic("epic對大story的一個描述性標簽")
@allure.feature("測試模塊")
class TestC:
    @allure.testcase("http://www.tc.com")
    @allure.issue("https://www.bug.com/")
    @allure.title("測試用例的標題")
    @allure.story("用戶故事:1")
    @allure.severity("blocker")
    def test_1(self,login):
        '''我是用例1的描述內容,看的見我不'''
        step_1()
        step_2()

    @allure.story("用戶故事:2")
    def test_2(self,login):
        print("測試用例2")
        step_1()
        step_3()
@allure.epic("epic對大story的一個描述性標簽")
@allure.feature("模塊塊2")
class TestC2():
    @allure.story("用戶故事:33")
    def test_3(self,login):
        print("測試用例test_3")
        step_1()

    @allure.story("用戶故事:44")
    def test_4(self,login):
        print("測試用例test_4")
        step_3()  

執行用例

cd到test_a.py的目錄

pytest --alluredir ./report/a  

生成報告

allure serve ./report/a  

報告展示內容

 

 命令行參數

pytest運行用例的時候可以加上allure標記用例的參數

--allure-severities=SEVERITIES_SET
                        Comma-separated list of severity names. Tests only
                        with these severities will be run. Possible values
                        are: blocker, critical, normal, minor, trivial.
--allure-epics=EPICS_SET
                        Comma-separated list of epic names. Run tests that
                        have at least one of the specified feature labels.
--allure-features=FEATURES_SET
                        Comma-separated list of feature names. Run tests that
                        have at least one of the specified feature labels.
--allure-stories=STORIES_SET
                        Comma-separated list of story names. Run tests that
                        have at least one of the specified story labels.
--allure-link-pattern=LINK_TYPE:LINK_PATTERN
                        Url pattern for link type. Allows short links in test,
                        like 'issue-1'. Text will be formatted to full url
                        with python str.format().  

選擇運行你要執行epic的用例

pytest --alluredir ./report/allure --allure-epics=epic對大Story的一個描述性標簽

選擇運行你要執行features的用例

pytest --alluredir ./report/allure --allure-features=模塊2

選擇運行你要執行features的用例

pytest --alluredir ./report/allure --allure-stories="用戶故事:1"

關於allure的使用基本上就是這些了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM