• ddt框架优化(生成html报告注释内容传变量)


    https://blog.csdn.net/weixin_33923148/article/details/86017742

    按要求修改后发现  注释只传值第一个变量

    这是因为

    ddt数据驱动生成html测试报告获取不到接口的名字

    需要修改ddt中的 mk_test_name() 方法

    #原文件方法
    def mk_test_name(name, value, index=0):
        # Add zeros before index to keep order
        index = "{0:0{1}}".format(index + 1, index_len)
        if not is_trivial(value):
            return "{0}_{1}".format(name, index)
        try:
            value = str(value)
        except UnicodeEncodeError:
            # fallback for python2
            value = value.encode('ascii', 'backslashreplace')
        test_name = "{0}_{1}_{2}".format(name, index, value)
        return re.sub(r'W|^(?=d)', '_', test_name)

    改为

    def mk_test_name(name, value, index=0):
        # Add zeros before index to keep order
        index = "{0:0{1}}".format(index + 1, index_len)
        if not is_trivial(value) and type(value) is not dict:
            return "{0}_{1}".format(name, index)
        if type(value) is dict:
            try:
                value = value["case_name"]
                print("ddts-name->{}".format(value))
            except:
                return "{0}_{1}".format(name, index)
        try:
            value = str(value)
        except UnicodeEncodeError:
            # fallback for python2
            value = value.encode('ascii', 'backslashreplace')
        test_name = "{0}_{1}_{2}".format(name, index, value)
        return re.sub(r'W|^(?=d)', '_', test_name)

    2、使用python使用ddt后,在生成的测试报告中,显示dict() -> new empty dictionary

    修改ddt文件中的ddt方法,test_docstring = " " 这样就ok了

    def ddt(cls):
        for name, func in list(cls.__dict__.items()):
            if hasattr(func, DATA_ATTR):
                for i, v in enumerate(getattr(func, DATA_ATTR)):
                    test_name = mk_test_name(name, getattr(v, "__name__", v), i)
                    test_docstring = getattr(v, "__doc__", None)
                    test_docstring = ""  #临时解决报告出现dict()new empty dictionary问题
                    if hasattr(func, UNPACK_ATTR):
                        if isinstance(v, tuple) or isinstance(v, list):
                            add_test(cls, test_name, test_docstring, func, *v)
                        else:
                            # unpack dictionary
                            add_test(cls, test_name, test_docstring, func, **v)
                    else:
                        add_test(cls, test_name, test_docstring, func, v)
                delattr(cls, name)
            elif hasattr(func, FILE_ATTR):
                file_attr = getattr(func, FILE_ATTR)
                process_file_data(cls, name, func, file_attr)
                delattr(cls, name)
        return cls

    或者 按照

    https://www.cnblogs.com/yoyoketang/p/9719509.html

    所说 重新安装 ddt 1.12

     

  • 相关阅读:
    (转) 解析 char *p和 char[]
    Linux下C程序内存、内存对齐问题 (实战)
    关于子网划分的两个例子
    子网掩码与子网划分 (转载)
    A、B、C类地址及子网掩码学习笔记
    本机ip、127.0.0.1和0.0.0.0区别(转载)
    初识const
    流媒体协议
    i2c-tools的使用方法
    linux ——内存共享映射mmap和munmap
  • 原文地址:https://www.cnblogs.com/clemente/p/10407453.html
Copyright © 2020-2023  润新知