使用 Django 在 teamcity 中测试覆盖率
我已经让 teamcity 工作了,它构建并运行了一个自定义测试运行程序(http://pypi.python. org/pypi/teamcity-messages)
我粗略地愚弄了这篇文章:TeamCity for Python/Django 持续集成
我的 run_suite 方法如下所示:
from teamcity import underTeamcity
from teamcity.unittestpy import TeamcityTestRunner
return TeamcityTestRunner().run(suite)
我目前将 django_coverage 与coverage.py 一起使用,我希望 teamcity 获取测试覆盖率数据。
我不受 teamcity 的约束,但我更喜欢将它用作 CI 服务器,但如果更容易的话我可以更改为另一个服务器。
如何获取 ./manage.py test_coverage 在 teamcity 中打印的数据?
I have got teamcity working and it builds and runs a custom testrunner (http://pypi.python.org/pypi/teamcity-messages)
I loosly foolowed this post: TeamCity for Python/Django continuous integration
My run_suite method looks like this:
from teamcity import underTeamcity
from teamcity.unittestpy import TeamcityTestRunner
return TeamcityTestRunner().run(suite)
I currently use django_coverage with coverage.py and I would like teamcity to get the test coverage data.
I am not bound to teamcity but I prefere using it as a CI server but I can change to another if it is easier.
How can I get the data that ./manage.py test_coverage prints in teamcity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TeamCity 覆盖率
在 TeamCity 中,我通过以下方式覆盖 Django
通过调用
make ci_test
命令使用Makefile
创建覆盖率报告。cover_test
命令运行 Django 测试,并测量代码的覆盖率。cover_report
命令将封面报告打印到控制台,还生成 html 报告,并使用 coverage-badge 实用程序,生成带有徽章代码覆盖状态的漂亮徽章 。之后,工件将收集在 TeamCity 中(选项卡
常规设置
)它们收集在选项卡
Artifacts
并可通过 CI 服务器路径获取:
/repository/download/%teamcity.project.id%/%teamcity.build .id%:id/htmlcov /index.html
/repository/download/%teamcity.project.id%/.lastFinished/htmlcov/index.html
GitHub 报告覆盖率
最后推送 GitHub hook在仓库中显示构建覆盖率状态:
覆盖率待定(构建前)
覆盖率徽章复制
覆盖率完成挂钩
github 中的结果:
关于此
ru
的博客文章:https ://maks.live/articles/drugoe/otchety-coverage-v-teamcity/TeamCity Coverage
In TeamCity I cover Django in the following way
Create coverage report by call
make ci_test
command useMakefile
.The
cover_test
command runs the Django tests, and measures the coverage of the code. Thecover_report
command prints a cover report to the console, and also generates an html report and, using the coverage-badge utility, generates a beautiful badge with the badge code coverage status .After that, artifacts are collected in the TeamCity (tab
General Settings
)They are collected in a tab
Artifacts
And available on CI server by path:
/repository/download/%teamcity.project.id%/%teamcity.build.id%:id/htmlcov /index.html
/repository/download/%teamcity.project.id%/.lastFinished/htmlcov/index.html
GitHub report coverage
Finally push GitHub hook to display build coverage state in repo:
Coverage Pending (before build)
Coverage badge copy
Coverage Finish hook
Result in github:
Blog post about this
ru
: https://maks.live/articles/drugoe/otchety-coverage-v-teamcity/我使用 teamcity-nose 并在 settings.py 中进行以下配置:
我的构建步骤测试如下所示:
我的项目的manage.py位于路径上(我通过setup.py安装在virtualenv bin中)
因此,如果您不这样做,则必须添加路径。
我从未设法在测试本身中添加覆盖范围,因为包版本控制存在问题,因此使用最新的覆盖范围包,我只是在额外的构建步骤中添加了它:
然后,如果您添加此内容,则可以添加一个包含覆盖范围 html 的选项卡到你的工件:
我还添加了一个带有行计数器的选项卡,你需要安装 cloc 或你选择的行计数器。
我还有一个额外的构建配置,用于通过 fab 每晚一次部署到登台服务器(只需像往常一样激活和 fab),以及一个额外的构建,用于在 pip 文件发生更改时自动安装 pip 要求,方法是将其添加到“pip install -rrequirements.pip”构建:
我将其添加到我的测试构建中,以便当 pip 和其他一些文件发生更改而不会影响构建测试时它不会运行:
I use teamcity-nose with the following configuration in settings.py:
My build step that does the testing looks like this:
My project's manage.py is on the path (I install in the virtualenv bin via setup.py)
so you will have to add the path if you do otherwise.
I never managed to add the coverage in the test itself as there are problems with package versioning, so with the latest coverage package i Just added it in an extra build step:
You can then add a tab that includes the coverage html if you add this to your artifact:
I also add a tab with the line counter too, you will need to have cloc or the linecounter of your choice installed.
I also have an extra build configuration for deploying to staging server once a night via fab (just activate and fab as usual), and an extra build for automatically installing pip requirements if the pip files change, by adding this to the triggering rules for the "pip install -r requirements.pip" build:
And I add this to my test build so that it doesn't run when pip and some other files change that don't effect the build test: