Python Unit Test Reporting to TeamCity 技术文档
本文档旨在帮助用户了解如何使用 teamcity-messages 项目,将 Python 单元测试结果报告到 TeamCity 持续集成服务器。文档内容包括安装指南、使用说明、API 使用文档以及项目安装方式。
1. 安装指南
使用 pip 安装
你可以通过 pip 命令安装 teamcity-messages 包:
pip install teamcity-messages
从源码安装
你也可以从源码安装该项目:
python setup.py install
2. 项目的使用说明
teamcity-messages 包通过发送服务消息来向 TeamCity 报告构建状态。以下是如何在不同测试框架中使用该包的说明。
unittest
如果你使用 Python 自带的 unittest 框架,可以通过修改测试运行器来集成 TeamCity 报告功能:
import unittest
from teamcity import is_running_under_teamcity
from teamcity.unittestpy import TeamcityTestRunner
class Test(unittest.TestCase):
...
if __name__ == '__main__':
if is_running_under_teamcity():
runner = TeamcityTestRunner()
else:
runner = unittest.TextTestRunner()
unittest.main(testRunner=runner)
你也可以在命令行中使用以下命令来运行测试:
python -m teamcity.unittestpy
nose
在 TeamCity 构建环境下,nose 的测试状态报告会自动启用。
py.test
在 TeamCity 构建环境下,py.test 的测试状态报告会自动启用。
Django
对于 Django 1.6+,你可以在 settings.py 中修改 TEST_RUNNER 设置,使用 TeamcityDjangoRunner 替代默认的 DiscoverRunner:
TEST_RUNNER = "teamcity.django.TeamcityDjangoRunner"
flake8
在 TeamCity 构建环境下,flake8 的测试状态报告会自动启用。
PyLint
在运行 pylint 时,添加 --output-format=teamcity.pylint_reporter.TeamCityReporter 参数:
pylint --output-format=teamcity.pylint_reporter.TeamCityReporter
tox
在 tox 的测试虚拟环境中传递 TEAMCITY_VERSION 环境变量:
[testenv]
passenv = TEAMCITY_VERSION
Twisted trial
在运行 trial 时,添加 --reporter=teamcity 参数:
trial --reporter=teamcity
Behave
对于 Behave 1.2.6,你可以通过以下代码启用 TeamCity 报告:
from behave.formatter import _registry
from behave.configuration import Configuration
from behave.runner import Runner
from teamcity.jb_behave_formatter import TeamcityFormatter
_registry.register_as("TeamcityFormatter", TeamcityFormatter)
configuration = Configuration()
configuration.format = ["TeamcityFormatter"]
configuration.stdout_capture = False
configuration.stderr_capture = False
Runner(configuration).run()
3. 项目 API 使用文档
teamcity-messages 提供了以下主要 API:
is_running_under_teamcity(): 检查当前是否在 TeamCity 环境下运行。TeamcityTestRunner: 用于unittest框架的测试运行器。TeamcityDjangoRunner: 用于 Django 的测试运行器。TeamcityFormatter: 用于 Behave 的格式化器。
4. 项目安装方式
使用 pip 安装
pip install teamcity-messages
从源码安装
python setup.py install
通过以上步骤,你可以成功安装并使用 teamcity-messages 包,将 Python 单元测试结果报告到 TeamCity 持续集成服务器。
Kimi-K2.5Kimi K2.5 是一款开源的原生多模态智能体模型,它在 Kimi-K2-Base 的基础上,通过对约 15 万亿混合视觉和文本 tokens 进行持续预训练构建而成。该模型将视觉与语言理解、高级智能体能力、即时模式与思考模式,以及对话式与智能体范式无缝融合。Python00
GLM-4.7-FlashGLM-4.7-Flash 是一款 30B-A3B MoE 模型。作为 30B 级别中的佼佼者,GLM-4.7-Flash 为追求性能与效率平衡的轻量化部署提供了全新选择。Jinja00
VLOOKVLOOK™ 是优雅好用的 Typora/Markdown 主题包和增强插件。 VLOOK™ is an elegant and practical THEME PACKAGE × ENHANCEMENT PLUGIN for Typora/Markdown.Less00
PaddleOCR-VL-1.5PaddleOCR-VL-1.5 是 PaddleOCR-VL 的新一代进阶模型,在 OmniDocBench v1.5 上实现了 94.5% 的全新 state-of-the-art 准确率。 为了严格评估模型在真实物理畸变下的鲁棒性——包括扫描伪影、倾斜、扭曲、屏幕拍摄和光照变化——我们提出了 Real5-OmniDocBench 基准测试集。实验结果表明,该增强模型在新构建的基准测试集上达到了 SOTA 性能。此外,我们通过整合印章识别和文本检测识别(text spotting)任务扩展了模型的能力,同时保持 0.9B 的超紧凑 VLM 规模,具备高效率特性。Python00
KuiklyUI基于KMP技术的高性能、全平台开发框架,具备统一代码库、极致易用性和动态灵活性。 Provide a high-performance, full-platform development framework with unified codebase, ultimate ease of use, and dynamic flexibility. 注意:本仓库为Github仓库镜像,PR或Issue请移步至Github发起,感谢支持!Kotlin07
compass-metrics-modelMetrics model project for the OSS CompassPython00