下载ddt并安装

Pip install ddt

或者官网下载安装

http://ddt.readthedocs.io/en/latest/

https://github.com/txels/ddt

DDT的使用

DDT包含类的装饰器ddt和两个方法装饰器data(直接输入测试数据),file_data(可以从json或者yaml中获取测试数据)

只有yaml和yml结尾的文件以yaml形式上传,其他情况下默认为json

通常情况下,data中的数据按照一个参数传递给测试用例,如果data中含有多个数据,以元组,列表,字典等数据,需要自行在脚本中对数据进行分解或者使用unpack分解数据

@data(a,b)

那么a和b各运行一次用例

@data([a,d],[c,d])

如果没有unpack,那么[a,b]当成一个参数传入用例运行

如果有unpack,那么[a,b]被分解开,按照用例中的两个参数传递

@file_data(filename)

对于json的文件,每一个json元素按照一个用例运行,可以依照python分解元组,列表或者字典的方式分解传入

import unittest
from ddt import ddt,data,file_data,unpack @ddt
class demotest(unittest.TestCase):
def setup(self):
print "this is the setup" @data(2,3)
def testb(self,value):
print value
print "this is test b" @data([2,3],[4,5])
def testa(self,value):
print value
print "this is test a" @data([2, 3], [4, 5])
@unpack
def testc(self, first,second):
print first
print second
print "this is test c" @file_data('d:/data_dic.json')
def test_dic(self,value):
print value
print 'this is dic' @file_data('d:/data.yml')
def test_yml(self, value):
print value
print 'this is yml' def teardown(self):
print "this is the down" if __name__ == '__main__':
unittest.main()
#suite=unittest.TestLoader.getTestCaseNames(demotest)
#suite = unittest.TestLoader().loadTestsFromTestCase(demotest)
#unittest.TextTestRunner(verbosity=2).run(suite)

python之数据驱动ddt的更多相关文章

  1. python之数据驱动ddt操作(方法一)

    下载ddt并安装 Pip install ddt 或者官网下载安装 http://ddt.readthedocs.io/en/latest/ https://github.com/txels/ddt ...

  2. python接口测试-数据驱动-DDT

    DDT是python的第三方库,全名称为:Data-Driven/Decorated Tests. ddt安装 通过pip安装ddt模块,安装Python后,Python自带pip功能包 切换到Pyt ...

  3. python之数据驱动ddt操作(方法四)

    from ddt import ddt,data,unpackfrom selenium import webdriverfrom selenium.webdriver.common.by impor ...

  4. python之数据驱动ddt操作(方法三)

    import unittestfrom selenium import webdriverfrom selenium.webdriver.common.by import Byimport unitt ...

  5. python之数据驱动ddt操作(方法二)

    import unittestfrom ddt import ddt,unpack,datafrom selenium import webdriverfrom selenium.webdriver. ...

  6. Python+Selenium+Unittest+Ddt+HTMLReport分布式数据驱动自动化测试框架结构

    1.Business:公共业务模块,如登录模块,可以把登录模块进行封装供调用 ------login_business.py from Page_Object.Common_Page.login_pa ...

  7. python webdriver 测试框架-数据驱动DDT的例子

    先在cmd环境 运行 pip install ddt 安装数据驱动ddt模块  脚本: #encoding=utf-8 from selenium import webdriver import un ...

  8. Python 数据驱动ddt 使用

    准备工作: pip install ddt 知识点: 一,数据驱动和代码驱动: 数据驱动的意思是  根据你提供的数据来测试的  比如 ATP框架 需要excel里面的测试用例 代码驱动是必须得写代码  ...

  9. 【转】Python unittest数据驱动工具:DDT

    背景 python 的unittest 没有自带数据驱动功能. 所以如果使用unittest,同时又想使用数据驱动,那么就可以使用DDT来完成. DDT是 “Data-Driven Tests”的缩写 ...

随机推荐

  1. S4 继承

    S3 系统是宽泛且灵活的,同类的 S3 对象也可能有不同的成员.但是,对于 S4 系统,就不会发生,也就是说,当我们创建一个属于某类的 S4 对象实例时,不能任意添加不在类表示中的字段.举个例子,在创 ...

  2. Rails-Treasure chest3 嵌套表单; Ransack(3900✨)用于模糊查询, ranked-model(800🌟)自订列表顺序; PaperTrail(5000✨)跟踪model's data,auditing and versioning.

    自订列表顺序, gem 'ranked-model' 多步骤表单 显示资料验证错误讯息 资料筛选和搜寻, gem 'ransack' (3900✨); 软删除和版本控制 数据汇出(csv), 自订列表 ...

  3. linux yum安装lsof命令

    [root@ITC-MCC ~]# yum install lsof[USM] permission denied^C[root@ITC-MCC ~]# [root@ITC-MCC ~]# [root ...

  4. UI测试_错题解析

    解析:因为jQuery easyUI是基于jQuery框架在使用之前应该先引入jquery框架否则jQuery easyUI将失效,故D错误 解析:考Link标签和script标签的区别,Link引入 ...

  5. ExtJS 6 如何引入Dashboard模版

    最近很多人问我在ext js 6+的版本中怎么引入官方的dashboard模版,正好我好久没写博客了,这里我写一篇博客来说明一下. 在这里以ext js 6.2.1版本为例(注:需要安装Sencha ...

  6. Linux中查看进程和杀掉进程

    ps -A查看正在运行的所有进程 kill -9 xxx杀掉某个进程,xxx为进程ID.

  7. C# 简单生成双色球代码

    红球篮球产生代码 public class TestD { //产生几组数据 public void getzhu( int num) { ; m < num; m++) { getred(); ...

  8. 前端常用框架和js插件 UI组件等

    前言:写这个随笔,是记录一下工作以来用到的各种框架.以免日后忘记: JS库: 1. jquery.js 2. zepto.js ----jquery的精简版,专门用于手机上的,但是zepto主体默认是 ...

  9. js设计模式整理

    单例模式 恶汉式单例 实例化时 懒汉式单例 调用时构造函数模式 1.实现一 function Car(model, year, miles) { this.model = model; this.ye ...

  10. 关于oceanbase中存储过程的设计与实现

    转自http://www.zhujuncoding.com/index.php/Index/blogview?id=82 这篇文章是关于在淘宝的数据库oceanbase中添加存储过程支持的文章,oce ...