更改由鼻子测试生成器创建的测试的名称 [英] Change names of tests created by nose test generators
问题描述
鼻子有一个错误-生成器创建的测试名称未缓存,因此错误看起来像是在上次测试中发生的错误,而不是在失败的实际测试中发生的错误.我在错误报告讨论中的解决方案之后解决了这个问题,但是它仅适用于标准输出上显示的名称,不适用于XML报告(--with-xunit)
Nose has a bug - test names created by generators are not cached, so the error looks like it happened in the last test, not the actual test where it failed. I got around it following the solution in the bug report discussion, but it only works for names shown on stdout, not in the XML report (--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
鼻子的输出符合预期,类似
The output of nose is as expected, something like
nice test name 0 ... ok
nice test name 1 ... ok
nice test name 2 ... ok
...
但是XML中的测试名称只是'testGenerator'.
But the test names in XML are just 'testGenerator'.
...<testcase classname="example" name="testGenerator" time="0.000" />...
如何更改此设置,以便个性化测试名称同时显示在stdout和XML输出上?
我正在使用鼻子测试版本1.1.2和Python 2.6.6
I'm using nosetests version 1.1.2 and Python 2.6.6
推荐答案
You can change the way that Nose names tests by adding a plugin that implements describeTest
from nose.plugins import Plugin
class CustomName(Plugin):
"Change the printed description/name of the test."
def describeTest(self, test):
return "%s:%s" % (test.test.__module__, test.test.description)
然后,您必须安装此插件,然后在鼻子"调用中启用它.
You will then have to install this plugin, and enable it in the Nose invocation.
这篇关于更改由鼻子测试生成器创建的测试的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!