zoukankan      html  css  js  c++  java
  • Pytest学习(二十一)- allure之@allure.description()、@allure.title()的使用

    一、@allure.description()的使用

    作用

    可以添加足够详细的测试用例描述

    语法格式,有三种

    1、@allure.description(str)

    2、在测试用例函数声明下方添加 """ """

    3、@allure.description_html(str):相当于传一个HTML代码组成的字符串,类似 allure.attach() 中传HTML

    示例代码如下:

    # -*- coding: utf-8 -*-
    # @Time    : 2020/12/12 11:15
    # @Author  : longrong.lang
    # @FileName: test_alluredescription.py
    # @Software: PyCharm
    # @Cnblogs :https://www.cnblogs.com/longronglang
    
    import allure
    
    
    # @allure.description(str)
    @allure.description("验证1=1")
    def test_description1():
        assert 1 == 1
    
    
    # 在测试用例函数声明下方添加 """ """
    def test_description2():
        """
        验证1=1
        """
        assert 1 == 1
    
    
    # @allure.description_html(str)
    @allure.description_html("""
    <h1>这是一段html描述</h1>
    <img src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1993234373,1554417853&fm=26&gp=0.jpg">
    """)
    def test_description3():
        assert 'h' in 'html'
    
    

    @allure.description(str)形式在allure中测试报告显示

    在测试用例函数声明下方添加 """ """,形式在allure中测试报告显示

    不难看出,前两种方式的效果和作用是一致的。

    @allure.description_html(str),形式在allure中测试报告显示

    二、@allure.title()

    作用

    • 使得测试用例的标题更具有可读性
    • 支持占位符传递关键字参数,(动态标题,结合 @pytest.mark.parametrize 使用)

    示例代码如下:

    # -*- coding: utf-8 -*-
    # @Time    : 2020/12/12 14:24
    # @Author  : longrong.lang
    # @FileName: test_allureTitle.py
    # @Software: PyCharm
    # @Cnblogs :https://www.cnblogs.com/longronglang
    import allure, pytest
    
    
    @allure.title("前置操作:获取用户名")
    @pytest.fixture()
    def users(request):
        user = request.param
        print(f" 用户名:{user}")
        return user
    
    
    @allure.title("前置操作:获取密码")
    @pytest.fixture()
    def pwds(request):
        pwd = request.param
        print(f" 密码:{pwd}")
        return pwd
    
    
    data1 = ["lilei", "hameimei", "jojo"]
    data2 = ["1", "2", "3"]
    
    
    @allure.title("组合操作:获取用户名: {users}  密码: {pwds}")
    @pytest.mark.parametrize("users", data1, indirect=True)
    @pytest.mark.parametrize("pwds", data2, indirect=True)
    def test_getuserinfo(users, pwds):
        print(f"用户名为:{users} 密码为:{pwds}")
    
    

    测试报告中展示

    注意:如果没有添加 @allure.title() 的话,测试用例的标题默认就是函数名

    优秀不够,你是否无可替代

    软件测试交流QQ群:721256703,期待你的加入!!

    欢迎关注我的微信公众号:软件测试君


  • 相关阅读:
    【原理】【重点】异步回调的一些实现策略
    上下文传递
    洋码头全异步服务框架
    秒杀系统架构优化思路
    从urllib2的内存泄露看python的GC python引用计数 对象的引用数 循环引用
    jvisualvm All-in-One Java Troubleshooting Tool
    小心踩雷,一次Java内存泄漏排查实战
    django 请求处理流程 链路追踪
    存储过程
    Dijkstra's algorithm
  • 原文地址:https://www.cnblogs.com/longronglang/p/14124631.html
Copyright © 2011-2022 走看看