鼻子产生与装饰

问题描述:

动态测试我有,所以我想使用循环 我会尝试像测试的动态量:鼻子产生与装饰

from nose.tools import istest, nottest 
from nose.tools import eq_ 
import nose 
nose.run() 
@istest 
def test_1(): 
    for i in range(100): 
     @istest 
     def test_1_1(): 
      eq_(randint(1,1),1) 



--------------------- 
Ran 1 test in 0.001s 

OK 

但鼻子显示它像只有一个测试。我如何将它改进到100次测试? 在此先感谢。

对于鼻子中的数据驱动测试,请查看nose_parameterized

实例:

from nose_parameterized import parameterized 

@parameterized.expand([(1, 1, 2), (2, 2, 4)]) 
def test_add(self, a, b, sum): 
    self.assertEqual(sum, a + b) 

在这里,两个测试将通过浇道产生的。它测试1+1==22+2==4。装饰者也与其他测试跑步者兼容,如unittest

+0

谢谢! 但对于我来说,仍然不清楚如何使用“for”循环。 –

+0

因为你不用for循环 - 这不是接口。让装饰者为你做循环,它更好。 – wim