python之parameterized模块

 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)
View Code

用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
View Code

用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
View Code

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

 

>>>>>待续

转载于:https://www.cnblogs.com/wuxunyan/p/9531685.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值