Python 我可以直接使用Nose Xunit类来输出Junit XML吗?
我们有一系列的系统测试,我想集成到Jenkins中。因此,我想我可能会尝试使用Nose的Xunit插件来生成结果文件。我的代码如下所示:Python 我可以直接使用Nose Xunit类来输出Junit XML吗?,python,nose,xunit,Python,Nose,Xunit,我们有一系列的系统测试,我想集成到Jenkins中。因此,我想我可能会尝试使用Nose的Xunit插件来生成结果文件。我的代码如下所示: from optparse import OptionParser from subprocess import call from nose.plugins.xunit import Xunit as xunit from nose.config import Config if __name__ == "__main__": p = Opti
from optparse import OptionParser
from subprocess import call
from nose.plugins.xunit import Xunit as xunit
from nose.config import Config
if __name__ == "__main__":
p = OptionParser(usage="A simple wrapper for creating JUnit XML")
p.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=False,
help="generate extra information")
# hook in xunit plugin options
x = xunit()
x.add_options(p)
(options, args) = p.parse_args()
x.configure(options, Config())
for test in args:
test_args = test.split(" ")
test_name = test_args[0]
if options.verbose: print "running: %s" % (test_name)
x.startTest(test_name)
result = call(test_args, shell=True)
if result == 0:
x.addSuccess(test_name)
else:
x.addFailure(test_name, None)
x.report()
但是,当我运行时,我会失败:
17:24 ajb@sloy/x86_64 [perf_test.git] >./junitify.py -v "/bin/true" "/bin/false"
running: /bin/true
Traceback (most recent call last):
File "./junitify.py", line 39, in
x.addSuccess(test_name)
File "/usr/lib/python2.7/dist-packages/nose/plugins/xunit.py", line 239, in addSuccess
self.stats['passes'] += 1
AttributeError: 'Xunit' object has no attribute 'stats'
17:24 ajb@sloy/x86_64[perf_test.git]>。/junitify.py-v“/bin/true”“/bin/false”
正在运行:/bin/true
回溯(最近一次呼叫最后一次):
文件“/junitify.py”,第39行,在
x、 addSuccess(测试名称)
addSuccess中的文件“/usr/lib/python2.7/dist-packages/nose/plugins/xunit.py”,第239行
self.stats['passes']+=1
AttributeError:“Xunit”对象没有属性“stats”
从xunit的代码来看,这是因为未设置self.enabled。但是,是否可以以这种方式使用Xunit库还不完全清楚。我想做的事可能吗?这仅仅是对这个库应该如何初始化的错误理解吗?我是否应该使用不同的python库来生成输出
这将是一个遗憾,因为我们确实使用nose在Jenkins下的python代码块上运行doctest单元测试。Ahh当我用一个额外的参数调用我的脚本时,我得到了进一步的结果:./junitify.py-v--with xunit”/bin/true”“/bin/false”,尽管它在以后再次失败时仍然失败。有一个self.enabled字段。也许这还没有确定?