Hudson “源代码不可用。”
我正在使用Hudson来持续构建一个Python项目。单元测试和代码覆盖率都运行得很好,但当我查看Cobertura覆盖报告时,发现一些不是单元测试的文件出现了这个信息:
Source code is unavailable.Some possible reasons are:
* This is not the most recent build (to save on disk space, this plugin only keeps the most recent builds source code).
* Cobertura found the source code but did not provide enough information to locate the source code.
* Cobertura could not find the source code, so this plugin has no hope of finding it.
奇怪的是,单元测试的源代码能被找到并显示出来。我尝试手动把其他.py文件的源代码复制到~/.hudson/jobs/<projectname>/cobertura
(单元测试的文件会被复制到这里),但没有成功。
有什么建议吗?
5 个回答
6
对我来说,其他两个解决方案单独使用都不管用,但把它们结合起来就有效了:
...
coverage xml
sed 's/<!-- Generated by coverage.py: http:\/\/nedbatchelder.com\/code\/coverage -->/<sources><source>\/path\/to\/sourcefolder<\/source><\/sources>/g'
这段代码只是把一个由 coverage.py 插入的注释替换成关于源代码位置的信息。
7
Cobertura报告文件(现在应该在$HUDSON/jobs/foo/workspace
这个地方)开头需要包含一些特定的内容:
<sources>
<source>/path/to/source</source>
<source>/another/path</source>
</sources>
它有这些内容吗?路径指向正确的地方了吗?
还有一个需要注意的地方:当它说“最近的构建”时,其实是指“最近的稳定构建”(也就是说,状态球是蓝色的,而不是黄色的)。
6
这真是个丑陋的解决办法,但这是我想到的唯一方法,终于让它工作了……经过几个小时的搜索和尝试,这就是我找到的唯一办法。
coverage run manage.py test
coverage xml
sed 's/filename="/filename="my\/path\//g' coverage.xml > coverage2.xml
这只是把类的xml标签中的文件名属性替换掉,然后在开头加上源文件的完整路径。记得把Cobertura的xml报告模式更新为coverage2.xml(如果你是把sed的输出导入到这个文件的话)。
要是Cobertura插件能像Violations插件那样让你输入源路径就好了——可惜据我所知,它并不支持。
希望这能帮到你!