小编M.K*_*.K.的帖子

更改由鼻子测试生成器创建的测试的名称

Nose有一个bug - 生成器创建的测试名称没有被缓存,因此错误看起来像是在上一次测试中发生的,而不是它失败的实际测试.我在bug报告讨论中解决了这个问题,但它只适用于stdout上显示的名称,而不适用于XML报告(--with-xunit)

from functools import partial, update_wrapper
def testGenerator():
    for i in range(10):
        func = partial(test)
        # make decorator with_setup() work again
        update_wrapper(func, test)
        func.description = "nice test name %s" % i
        yield func

def test():
    pass
Run Code Online (Sandbox Code Playgroud)

鼻子的输出正如预期的那样

nice test name 0 ... ok
nice test name 1 ... ok
nice test name 2 ... ok
...
Run Code Online (Sandbox Code Playgroud)

但XML中的测试名称只是'testGenerator'.

...<testcase classname="example" name="testGenerator" time="0.000" />...
Run Code Online (Sandbox Code Playgroud)

如何更改此设置,以便在stdout和XML输出上显示个性化测试名称?

我正在使用nosetests版本1.1.2和Python 2.6.6

python unit-testing generator nose nosetests

8
推荐指数
1
解决办法
4162
查看次数

标签 统计

generator ×1

nose ×1

nosetests ×1

python ×1

unit-testing ×1