用于 Python/Django 持续集成的 TeamCity

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1091465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 21:28:07  来源:igfitidea点击:

TeamCity for Python/Django continuous integration

pythondjangocontinuous-integrationteamcity

提问by Art

I've set up TeamCityon a Linux (Ubuntu) box and would like to use it for some of Python/Django projects.

我已经在 Linux (Ubuntu) 机器上设置了TeamCity,并希望将它用于一些 Python/Django 项目。

The problem is that I don't really see what to do next - I tried searching for a Python specific build agent for TeamCity but without much of the success.

问题是我真的不知道接下来要做什么 - 我尝试为 TeamCity 搜索特定于 Python 的构建代理,但没有取得太大的成功。

How can I manage that?

我该如何管理?

回答by Art

Ok, so there's how to get it working with proper TeamCity integration:

好的,下面是如何通过适当的 TeamCity 集成使其工作:

Presuming you have TeamCity installed with at least 1 build agent available

假设您安装了 TeamCity,并且至少有 1 个可用的构建代理

1) Configure your build agent to execute

1) 配置您的构建代理以执行

manage.py test

2) Download and install this plugin for TC http://pypi.python.org/pypi/teamcity-messages

2) 下载并安装TC插件http://pypi.python.org/pypi/teamcity-messages

3) You'll have to provide your custom test runner for plugin in (2) to work. It can be straight copy of run_tests from django.test.simple, with only one slight modification: replace line where test runner is called with TeamcityTestRunner, so insted of

3) 您必须为 (2) 中的插件提供自定义测试运行器才能工作。它可以是 django.test.simple 中 run_tests 的直接副本,只需稍作修改:用 TeamcityTestRunner 替换调用测试运行器的行,因此插入

def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    ...
    result = unittest.TextTestRunner(verbosity=verbosity).run(suite)

use this:

用这个:

def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    ...
    result = TeamcityTestRunner().run(suite)

You'll have to place that function into a file in your solution, and specify a custome test runner, using Django's TEST_RUNNER configuration property like this:

您必须将该函数放入解决方案中的文件中,并使用 Django 的 TEST_RUNNER 配置属性指定一个自定义测试运行器,如下所示:

TEST_RUNNER = 'my_site.file_name_with_run_tests.run_tests'

Make sure you reference all required imports in your file_name_with_run_tests

确保在file_name_with_run_tests 中引用所有必需的导入

You can test it by running

您可以通过运行来测试它

./manage.py test

from command line and noticing that output has changed and now messages like

从命令行并注意到输出已更改,现在消息如下

#teamcity....

appearing in it.

出现在其中。

回答by Olexiy Strashko

I have added feature request to TeamCity issue tracker, to make full-featured python support. This is the link: http://youtrack.jetbrains.com/issue/TW-25141. If you interested, you can vote for it, and that may force JetBrains to improve python support.

我已向 TeamCity 问题跟踪器添加了功能请求,以提供全功能的 Python 支持。这是链接:http: //youtrack.jetbrains.com/issue/TW-25141。如果您有兴趣,可以投票支持它,这可能会迫使 JetBrains 改进对 Python 的支持。