如何使用@allure.description()为pytest测试用例添加详细描述?
- 内容介绍
- 文章标签
- 相关推荐
本文共计674个文字,预计阅读时间需要3分钟。
前言:allure支持往测试报告中添加对测试用例的详细描述语用。这可以帮助阅读测试报告的人更好地理解每个测试用例的细节情况;这对阅读测试报告的人来说非常友好,可以清晰地知道每个测试用例的详细信息。allure添加描述的功能:
前言
allure支持往测试报告中对测试用例添加非常详细的描述语用来描述测试用例详情;这对阅读测试报告的人来说非常的友好,可以清晰的知道每个测试用例的详情。
allure添加描述的三种方式:
- 使用装饰器@allure.description,传递一个字符串参数来描述测试用例。
- 使用装饰器@allure.description_html,传递一段HTML文本,这将在测试报告的“Description”部分渲染出来。
- 直接在测试用例方法中通过编写文档注释的方法来添加描述。
实例
# file_name: test_description.pyimport 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
1、查看测试报告展示效果:
2、查看测试报告展示效果:
3、查看测试报告展示效果:
allure动态更新描述语(allure.dynamic.description):
# file_name: test_description.pyimport 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
查看测试报告展示效果:
去期待陌生,去拥抱惊喜。
本文共计674个文字,预计阅读时间需要3分钟。
前言:allure支持往测试报告中添加对测试用例的详细描述语用。这可以帮助阅读测试报告的人更好地理解每个测试用例的细节情况;这对阅读测试报告的人来说非常友好,可以清晰地知道每个测试用例的详细信息。allure添加描述的功能:
前言
allure支持往测试报告中对测试用例添加非常详细的描述语用来描述测试用例详情;这对阅读测试报告的人来说非常的友好,可以清晰的知道每个测试用例的详情。
allure添加描述的三种方式:
- 使用装饰器@allure.description,传递一个字符串参数来描述测试用例。
- 使用装饰器@allure.description_html,传递一段HTML文本,这将在测试报告的“Description”部分渲染出来。
- 直接在测试用例方法中通过编写文档注释的方法来添加描述。
实例
# file_name: test_description.pyimport 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
1、查看测试报告展示效果:
2、查看测试报告展示效果:
3、查看测试报告展示效果:
allure动态更新描述语(allure.dynamic.description):
# file_name: test_description.pyimport 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
查看测试报告展示效果:
去期待陌生,去拥抱惊喜。

