#!/usr/bin/env/python
# -*- coding: utf-8 -*-
# @Time : 2018/12/15 15:27
# @Author : ChenAdong
# @Email : aiswell@foxmail.com import unittest
import ddt lst = [1, 2, 3]
dic = {"userName": "chen"}
tur = (1, 2, 3)
s = {1, 2, 3} @ddt.ddt
class Test(unittest.TestCase): @ddt.data(*lst)
def test_list(self, data):
print("test_list")
print(data)
print("==================") @ddt.data(*dic)
def test_dictionary(self, data):
print("test_dic")
print(data)
print("==================") @ddt.file_data("ddt_test001.json")
def test_file(self, key):
print(key) @ddt.file_data("ddt_test.json")
@ddt.unpack
def test_file(self, start, end, value):
print(start, end, value) if __name__ == "__main__":
unittest.main() """
# 付上ddt-help

E:\myworkspace\python_workspace\tools\venv\Scripts\python.exe E:/myworkspace/python_workspace/projects/tmp/test002.py
Help on module ddt:

NAME
ddt

DESCRIPTION
# -*- coding: utf-8 -*-
# This file is a part of DDT (https://github.com/txels/ddt)
# Copyright 2012-2015 Carles Barrobés and DDT contributors
# For the exact contribution history, see the git revision log.
# DDT is licensed under the MIT License, included in
# https://github.com/txels/ddt/blob/master/LICENSE.md

FUNCTIONS
add_test(cls, test_name, test_docstring, func, *args, **kwargs)
Add a test case to this class.

The test will be based on an existing function but will give it a new
name.

data(*values)
Method decorator to add to your test methods.

Should be added to methods of instances of ``unittest.TestCase``.

ddt(cls)
Class decorator for subclasses of ``unittest.TestCase``.

Apply this decorator to the test case class, and then
decorate test methods with ``@data``.

For each method decorated with ``@data``, this will effectively create as
many methods as data items are passed as parameters to ``@data``.

The names of the test methods follow the pattern
``original_test_name_{ordinal}_{data}``. ``ordinal`` is the position of the
data argument, starting with 1.

For data we use a string representation of the data value converted into a
valid python identifier. If ``data.__name__`` exists, we use that instead.

For each method decorated with ``@file_data('test_data.json')``, the
decorator will try to load the test_data.json file located relative
to the python file containing the method that is decorated. It will,
for each ``test_name`` key create as many methods in the list of values
from the ``data`` key.

feed_data(func, new_name, test_data_docstring, *args, **kwargs)
This internal method decorator feeds the test data item to the test.

file_data(value)
Method decorator to add to your test methods.

Should be added to methods of instances of ``unittest.TestCase``.

``value`` should be a path relative to the directory of the file
containing the decorated ``unittest.TestCase``. The file
should contain JSON encoded data, that can either be a list or a
dict.

In case of a list, each value in the list will correspond to one
test case, and the value will be concatenated to the test method
name.

In case of a dict, keys will be used as suffixes to the name of the
test case, and values will be fed as test data.

idata(iterable)
Method decorator to add to your test methods.

Should be added to methods of instances of ``unittest.TestCase``.

is_trivial(value)

mk_test_name(name, value, index=0)
Generate a new name for a test case.

It will take the original test name and append an ordinal index and a
string representation of the value, and convert the result into a valid
python identifier by replacing extraneous characters with ``_``.

We avoid doing str(value) if dealing with non-trivial values.
The problem is possible different names with different runs, e.g.
different order of dictionary keys (see PYTHONHASHSEED) or dealing
with mock objects.
Trivial scalar values are passed as is.

A "trivial" value is a plain scalar, or a tuple or list consisting
only of trivial values.

process_file_data(cls, name, func, file_attr)
Process the parameter in the `file_data` decorator.

unpack(func)
Method decorator to add unpack feature.

DATA
DATA_ATTR = '%values'
FILE_ATTR = '%file_path'
UNPACK_ATTR = '%unpack'
index_len = 5
trivial_types = (<class 'NoneType'>, <class 'bool'>, <class 'int'>, <c...

VERSION
1.2.1

FILE
e:\myworkspace\python_workspace\tools\venv\lib\site-packages\ddt.py

None

Process finished with exit code 0

"""

python ddt的更多相关文章

  1. python DDT读取excel测试数据

    转自:http://www.cnblogs.com/nuonuozhou/p/8645129.html ddt   结合单元测试一起用 ddt(data.driven.test):数据驱动测试 由外部 ...

  2. python ddt数据驱动(简化重复代码)

    在接口自动化测试中,往往一个接口的用例需要考虑 正确的.错误的.异常的.边界值等诸多情况,然后你需要写很多个同样代码,参数不同的用例.如果测试接口很多,不但需要写大量的代码,测试数据和代码柔合在一起, ...

  3. python ddt 实现数据驱动一

    ddt 是第三方模块,需安装, pip install ddt DDT包含类的装饰器ddt和两个方法装饰器data(直接输入测试数据) 通常情况下,data中的数据按照一个参数传递给测试用例,如果da ...

  4. python+ddt+unittest+excel+request实现接口自动化

    接口自动化测试流程:需求分析-用例设计--脚本开发--测试执行--结果分析1.获取接口文档,根据文档获取请求方式,传输协议,请求参数,响应参数,判断测试是否通过设计用例2.脚本开发:使用request ...

  5. python ddt 实现数据驱动

    ddt 是第三方模块,需安装, pip install ddt DDT包含类的装饰器ddt和两个方法装饰器data(直接输入测试数据) 通常情况下,data中的数据按照一个参数传递给测试用例,如果da ...

  6. python ddt实现数据驱动

    首先安装ddt模块,命令:pip install ddt 通常情况下,data中的数据按照一个参数传递给测试用例,如果data中含有多个数据,以元组,列表,字典等数据,需要自行在脚本中对数据进行分解或 ...

  7. python ddt 传多个参数值示例

    import unittest from ddt import ddt,data,file_data,unpack @ddt class TestDDT(unittest.TestCase): lis ...

  8. python ddt模块

    ddt模块包含了一个类的装饰器ddt和两个方法的装饰器: data:包含多个你想要传给测试用例的参数: file_data:会从json或yaml中加载数据: 通常data中包含的每一个值都会作为一个 ...

  9. Python DDT(data driven tests)模块心得

    关于ddt模块的一些心得,主要是看官网的例子,加上一点自己的理解,官网地址:http://ddt.readthedocs.io/en/latest/example.html ddt(data driv ...

随机推荐

  1. EDI 学习开发(一)

    最近有个需求,关于EDI 的开发,效果烂成一坨屎,写个总结,记录这坨屎. 配置文件:01.EDI.Export.Config(在EDI 服务器SystemConfig目录下) 02.EDI.TypeC ...

  2. 深入理解Java虚拟机阅读心得(三)

    Java中提倡的自动内存管理最终可以归结为自动化的解决两个问题: 给对象分配内存 回收分配给对象的内存 先说说回收这一方面的两个主要知识点 一.垃圾收集算法 1.标记-清理算法 首先标记出所有需要回收 ...

  3. [转]在nodejs使用Redis缓存和查询数据及Session持久化(Express)

    本文转自:https://blog.csdn.net/wellway/article/details/76176760 在之前的这篇文章 在ExpressJS(NodeJS)中设置二级域名跨域共享Co ...

  4. HttpClient之可恨的Expect(C# http 请求卡住的解决办法)

    今天用HTTP.HttpClient这个对象开发的时候遇到一个奇怪的问题 当POST一个页面的时候始终卡住提交不成功 最初以为协议有错误就抓包测试在抓包在测试 最后想到是不是HttpClient的BU ...

  5. 【Mybatis】MyBatis调用带有返回结果、output参数的存储过程上与ibatis的区别

    用过mybatis的应该都知道它是ibatis被Google收购后重新命名的一个工程,因此也做了大量升级.本文就来介绍下两者在调用存储过程上的一点区别,ibatis有一个专门的标签<proced ...

  6. Java高并发 -- 线程池

    Java高并发 -- 线程池 主要是学习慕课网实战视频<Java并发编程入门与高并发面试>的笔记 在使用线程池后,创建线程变成了从线程池里获得空闲线程,关闭线程变成了将线程归坏给线程池. ...

  7. Docker 系列七(Dubbo 微服务部署实践).

    一.前言 之前我们公司部署服务,就是大家都懂的那一套(安装JDK.Tomcat —> 编译好文件或者打war包上传 —> 启动Tomcat),这种部署方式一直持续了很久,带来的问题也很多: ...

  8. js 位运算符

    MDN定义:位运算符将它的操作数视为32位元的二进制串(0和1组成)而非十进制八进制或十六进制数. 例如:十进制数字9用二进制表示为1001,位运算符就是在这个二进制表示上执行运算,但是返回结果是标准 ...

  9. 配置安全域名https申请免费证书并配置nginx运行环境

    补全信息时选项 在这一步需要去查看进度,下载对应文件上传到对应站点根目录里按照要求建的隐藏类型的文件 如下图 讲证书文件按照下面操作 进行配置项配置https 如下 详情下载附件 server { l ...

  10. CSS选择器【记录】

    1.基本选择器 2.组合选择器 3.伪类选择器 4.伪元素选择器 CSS选择器规定了CSS规则会应用到哪些元素上 1.基本选择器 基本选择器:通配选择器.元素选择器.类选择器.ID选择器.属性选择器 ...