Hudson“源代码不可用。”

发布于 2024-08-22 03:55:19 字数 680 浏览 16 评论 0原文

我正在使用 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//cobertura (复制单元测试的位置),但它不起作用。

有什么建议吗?

I'm using Hudson to continuously build a Python project. Unit tests and code coverage work great, but this message appears when drilling into the Cobertura Coverage Report for my files that are not unit tests:

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.

The strange thing is that the source code for the unit tests are found and displayed. I tried to manually copy the source files for other .py files into ~/.hudson/jobs/<projectname>/cobertura (where the unit tests get copied), but it did not work.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

岁月静好 2024-08-29 03:55:19

Cobertura 报告文件(此时位于 $HUDSON/jobs/foo/workspace 中的某个位置)需要在开头包含类似这样的内容:

<sources>
  <source>/path/to/source</source>
  <source>/another/path</source>
</sources>

有吗?路径是否指向正确的位置?

另一个问题:当它说“最近的版本”时,它实际上意味着“最近的稳定版本”(即状态球是蓝色的,而不是黄色的)。

The Cobertura report file (which at this point is somewhere in $HUDSON/jobs/foo/workspace) needs to contain something like this at the beginning:

<sources>
  <source>/path/to/source</source>
  <source>/another/path</source>
</sources>

Does it have that? Do the paths point to the right place?

Another gotcha: when it says "most recent build", it actually means "most recent stable build" (i.e. the status ball is blue, as opposed to yellow).

赢得她心 2024-08-29 03:55:19

这是一个丑陋的黑客,但它是我唯一能想出的最终让它发挥作用的东西......经过几个小时的谷歌搜索和黑客试图获得结果,这是我想出的唯一的东西。

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 插件那样输入源路径,那就太好了 - 不幸的是,据我所知,它不允许。

我希望这有帮助!

This is one hell of an ugly hack, but its the only thing that I could come up with to finally make it work... and after hours of Googling and hacking away trying to get results, this is the only thing I came up with.

coverage run manage.py test
coverage xml
sed 's/filename="/filename="my\/path\//g' coverage.xml > coverage2.xml

This is just relpacing the filename attribute of the class xml tags and adding the full path to the source files at the beginning. Just make sure that you update the Cobertura xml report pattern to be coverage2.xml (if that is where you're piping sed's output to).

It would be nice if the Cobertura plugin would allow you to enter the source path similar to how the Violations plugin does - unfortunately, as far as I'm aware, it doesn't.

I hope this helps!

不爱素颜 2024-08-29 03:55:19

对我来说,其他两个解决方案不能单独工作,但将它们结合起来可以:

...
coverage xml
sed 's/<!-- Generated by coverage.py: http:\/\/nedbatchelder.com\/code\/coverage -->/<sources><source>\/path\/to\/sourcefolder<\/source><\/sources>/g'

这只是替换 coverage.py 包含有关源位置的信息。

For me the other two solutions did not work stand-alone, but a combination of both of them did:

...
coverage xml
sed 's/<!-- Generated by coverage.py: http:\/\/nedbatchelder.com\/code\/coverage -->/<sources><source>\/path\/to\/sourcefolder<\/source><\/sources>/g'

This just replaces a comment inserted by coverage.py with information about the source location.

寂寞清仓 2024-08-29 03:55:19

我们的解决方案是更改 cobertura-report ant 任务的使用,以包含源目录的完整路径而不是相对路径。

 <cobertura-report format="xml" destdir="${coverage.dir}" srcdir="${basedir}/${src.dir}"/>

基本上,cobertura xml 报告中包含的相对路径与 Hudson 交叉,因此 Cobertura 插件无法使用它来查找源代码。在我们的案例中,这是 Hudson 如何为单模块项目和多模块项目进行路径处理之间的差异的症状。

Our solution was to alter our use of the cobertura-report ant task to include the full path to the source directory rather than the relative path.

 <cobertura-report format="xml" destdir="${coverage.dir}" srcdir="${basedir}/${src.dir}"/>

Basically, the relative pathing included in the cobertura xml report crosses up Hudson such that the Cobertura Plugin can't use it to find the source code. In our case, this was was symptomatic of the differences between how Hudson does its pathing for single module projects and multi-module projects.

〃温暖了心ぐ 2024-08-29 03:55:19

解决此问题的“正确”方法是将项目放在 PYTHONPATH 上并从存储库外部运行测试/覆盖。由于看起来您正在使用 Django,因此 django-admin.py test --settings=myproject.settings 将允许您执行此操作。

-- 最初由 Pete 在评论中发布,移至答案。

The "correct" way to fix this is by putting your project on the PYTHONPATH and running the tests/coverage from outside your repo. Since it looks like you're using Django, django-admin.py test --settings=myproject.settings will let you do this.

-- Originally posted by Pete in a comment, moved to answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文