parameterized扩展了py.test参数化测试,unittest参数化测试。

<1>一个小练习

import unittest
import math @parameterized([
(2, 2, 4),
(2, 3, 8),
(1, 9, 1),
(0, 9, 0),
])
def test_pow(base, exponent, expected):
assert_equal(math.pow(base, exponent), expected) class TestMathUnitTest(unittest.TestCase):
@parameterized.expand([
("negative", -1.5, -2.0),
("integer", 1, 1.0),
("large fraction", 1.6, 1),
])
def test_floor(self, name, input, expected):
assert_equal(math.floor(input), expected)

用unittest运行,结果如下:

D:\pythonstudy\WonderStitch>python3 -m unittest -v test
test_floor_0_negative (test.TestMathUnitTest) ... ok
test_floor_1_integer (test.TestMathUnitTest) ... ok
test_floor_2_large_fraction (test.TestMathUnitTest) ... ok ----------------------------------------------------------------------
Ran 3 tests in 0.002s OK

用nose运行,结果如下:

D:\pythonstudy\WonderStitch>nosetests -v test.py
test_floor_0_negative (test.TestMathUnitTest) ... ok
test_floor_1_integer (test.TestMathUnitTest) ... ok
test_floor_2_large_fraction (test.TestMathUnitTest) ... ok
test.test_pow(2, 2, 4) ... ok
test.test_pow(2, 3, 8) ... ok
test.test_pow(1, 9, 1) ... ok
test.test_pow(0, 9, 0) ... ok ----------------------------------------------------------------------
Ran 7 tests in 0.004s OK

注意:因为UNITTEST不支持测试装饰器,故只有使用@parameterized.expand创建的测试才会被执行。

>>>>>待续

python之parameterized模块的更多相关文章

  1. python之platform模块

    python之platform模块 ^_^第三个模块从天而降喽!! 函数列表 platform.system() 获取操作系统类型,windows.linux等 platform.platform() ...

  2. python之OS模块详解

    python之OS模块详解 ^_^,步入第二个模块世界----->OS 常见函数列表 os.sep:取代操作系统特定的路径分隔符 os.name:指示你正在使用的工作平台.比如对于Windows ...

  3. python之sys模块详解

    python之sys模块详解 sys模块功能多,我们这里介绍一些比较实用的功能,相信你会喜欢的,和我一起走进python的模块吧! sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传 ...

  4. 学习PYTHON之路, DAY 6 - PYTHON 基础 6 (模块)

    一 安装,导入模块 安装: pip3 install 模块名称 导入: import module from module.xx.xx import xx from module.xx.xx impo ...

  5. linux下python调用c模块

    在C调用Python模块时需要初始化Python解释器,导入模块等,但Python调用C模块却比较简单,下面还是以helloWorld.c 和 main.py 做一说明:   (1)编写C代码,hel ...

  6. Python学习之模块进程函数详解

    今天在看<Beginning Linux Programming>中的进程相关部分,讲到Linux几个进程相关的系统函数: system , exec , fork ,wait . Pyt ...

  7. python基础——第三方模块

    python基础——第三方模块 在Python中,安装第三方模块,是通过包管理工具pip完成的.  如果你正在使用Mac或Linux,安装pip本身这个步骤就可以跳过了.  如果你正在使用Window ...

  8. python基础——使用模块

    python基础——使用模块 Python本身就内置了很多非常有用的模块,只要安装完毕,这些模块就可以立刻使用. 我们以内建的sys模块为例,编写一个hello的模块: #!/usr/bin/env ...

  9. python 中time模块使用

    在开始之前,首先要说明这几点: 1.在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主 ...

随机推荐

  1. django orm多条件查询及except处理不存在记录的样码

    日常所用的功能, 记录下来加深记忆. try: sv_set = Sv.objects.get(project=site_name, version=deploy_version) print sv_ ...

  2. [bzoj1218][HNOI2003]激光炸弹_暴力

    激光炸弹 bzoj-1218 HNOI-2003 题目大意:在笛卡尔坐标系上有n个点,问一个平行于坐标轴的r*r的正方形可以最多覆盖多少个目标. 注释:$1\le n \le 10000$,$1\le ...

  3. kafka内置的zookeeper

    kafka 很多说不需要安装zk的是因为他们都使用了kafka自带的zk 至于kafka为什么使用zk,你首先要知道zk的作用, 作为去中心化的集群模式. 需要要消费者知道现在那些生产者(对于消费者而 ...

  4. Codeforces Round #349 (Div. 2) C. Reberland Linguistics DP+set

    C. Reberland Linguistics     First-rate specialists graduate from Berland State Institute of Peace a ...

  5. Java 异步转同步 ListenableFuture in Guava

    ListenableFuture的说明 并发编程是一个难题,但是一个强大而简单的抽象可以显著的简化并发的编写.出于这样的考虑,Guava 定义了 ListenableFuture接口并继承了JDK c ...

  6. c28---const

    // // main.c // const关键字,节省内存空间,放在字符表里面, #include <stdio.h> int main(int argc, const char * ar ...

  7. [BZOJ 2100] Apple Delivery

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2100 [算法] Answer = min{ dist(PB,PA1) + dist( ...

  8. Node.js:教程

    ylbtech-Node.js:教程 1.返回顶部 1. Node.js 教程 简单的说 Node.js 就是运行在服务端的 JavaScript. Node.js 是一个基于Chrome JavaS ...

  9. Vue.js和Nodejs的关系

    首先vue.js 是库,不是框架,不是框架,不是框架. Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据. Vue.js 的核心是一个允许你 ...

  10. NSKeyedUnarchiver归档

    把自定义的类对象编码到NSData中 NSData *data = [NSKeyedArchiver archivedDataWithRootObject:bc];//归档,bc是一个自定义的类对象, ...