allure為測試用例添加描述(allure.description)


  allure支持往測試報告中對測試用例添加非常詳細的描述語用來描述測試用例詳情,這對閱讀測試報告的人來說非常的友好,可以清晰的知道每個測試用例的詳情。

allure添加描述的三種方式:

  • 使用裝飾器@allure.description,傳遞一個字符串參數用來描述測試用例;
  • 使用裝飾器@allure.description_html,傳遞一段HTML文本,這將在測試報告的"Description"部分渲染出來;
  • 直接在測試用例方法中通過編寫文檔注釋的方式來添加描述;

舉個栗子:

# file_name: test_description.py


import pytest
import allure


@allure.description("""
多行描述語:
這是通過傳遞字符串參數的方式添加的一段描述語,
使用的是裝飾器@allure.description
""")
def test_description_provide_string():
    assert True


@allure.description_html("""
<h1>Test with some complicated html description</h1>
<table style="width:100%" border="1">
  <tr>
    <th>Name</th>
    <th>Age</th>
    <th>Sex</th>
  </tr>
  <tr align="center">
    <td>lwjnicole</td>
    <td>28</td>
    <td>男</td>
  </tr>
  <tr align="center">
    <td>nicole</td>
    <td>29</td>
    <td>女</td>
  </tr>
</table>
""")
def test_description_privide_html():
    assert True


def test_description_docstring():
    """
    這是通過文本注釋的方式添加的描述語

    同樣支持多行描述

    大家好,我是lwjnicole
    :return:
    """
    assert True


if __name__ == '__main__':
    pytest.main(['-s', 'test_description.py'])

執行命令:

> pytest test_description.py --alluredir=./report/result_data

> allure serve ./report/result_data

查看測試報告展示效果:

  上面的測試報告是通過裝飾器@allure.description傳遞字符串參數來添加描述語的方式。

  上面的測試報告是通過裝飾器@allure.description_html傳遞一段HTML文本來添加描述語的方式,這段HTML會渲染在報告的"Description"部分。

  上面的測試報告是通過直接在測試用例方法中編寫文檔注釋來添加描述語的方式。

allure動態更新描述語(allure.dynamic.description):

# file_name: test_description.py


import pytest
import allure


@allure.description("這是更新前的描述語,在使用allure.dynamic.description后將會被更新成新的描述語")
def test_dynamic_description():
    assert True
    allure.dynamic.description("這是通過使用allure.dynamic.description更新后的描述語")


if __name__ == '__main__':
    pytest.main(['-s', 'test_description.py'])

執行命令:

> pytest test_description.py --alluredir=./report/result_data

> allure serve ./report/result_data

查看測試報告展示效果:

  從上面的測試報告中可以看到,Description中展示的是使用allure.dynamic.description更新后的描述語。


免責聲明!

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



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