Registry / devops / teamcity-messages

teamcity-messages

JSON →
library1.33pypypi✓ verified 21d ago

This package integrates Python with the TeamCity Continuous Integration (CI) server, enabling the reporting of test results and other build information via TeamCity service messages. It provides integrations for popular testing frameworks like `unittest`, `pytest`, `nose`, `behave`, `twisted trial`, and code quality tools such as `flake8` and `pylint`. The current version is 1.33, with a release cadence that supports new Python versions and tool compatibility.

pip install teamcity-messages
INSTALL
IMPORT
SIG · TEAMCITY-MESSAGES
T
teamcity-messages
devopspythonv1.33
Install
1.9s avg
Import
134ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.33 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.146s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.122s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TeamcityTestRunner
from teamcity.unittestpy import TeamcityTestRunner
Required to integrate with Python's standard unittest framework.
is_running_under_teamcity
from teamcity import is_running_under_teamcity
Useful for conditionally enabling TeamCity reporting logic.
TeamcityServiceMessages
from teamcity.messages import TeamcityServiceMessages
For sending custom service messages directly to TeamCity.

This example demonstrates how to integrate `teamcity-messages` with the standard `unittest` framework. It uses `is_running_under_teamcity()` to conditionally apply the `TeamcityTestRunner`, which sends test results to the TeamCity server via service messages when detected.

import unittest from teamcity import is_running_under_teamcity from teamcity.unittestpy import TeamcityTestRunner import os class MyTests(unittest.TestCase): def test_success(self): self.assertTrue(True, "This test should pass") def test_failure(self): self.assertEqual(1, 2, "This test should fail") def test_skipped(self): if os.environ.get('SKIP_TESTS') == '1': self.skipTest("Skipping this test due to environment variable") self.assertTrue(True) if __name__ == '__main__': print('Running tests...') if is_running_under_teamcity(): print('Running under TeamCity, using TeamcityTestRunner') runner = TeamcityTestRunner() else: print('Not running under TeamCity, using default TextTestRunner') runner = unittest.TextTestRunner() unittest.main(testRunner=runner, exit=False)
Debug
Known issues
breakingOlder Python versions are no longer supported. Version 1.28 dropped support for Python 2.6 and 3.5. Version 1.26 dropped support for Python 3.4.
fix
Upgrade to Python 3.6+ to use current versions of `teamcity-messages`.
affects: <=1.27 for Python 2.6/3.5, <=1.25 for Python 3.4
gotchaCompatibility issues can arise with newer versions of integrated testing and analysis tools (e.g., `coverage`, `flake8`, `pylint`, `pytest`) if `teamcity-messages` is not updated. Ensure your `teamcity-messages` version is compatible with your test ecosystem.
fix
Refer to the `teamcity-messages` changelog before upgrading related tools. For example, v1.33 fixed `coverage` 7.5+, v1.32 fixed `flake8` >= 5, and v1.30 fixed `pylint` >= 2.12.
affects: All versions, as new tool versions are released.
gotchaFor automatic test reporting with `nose`, `pytest`, and `flake8`, ensure the `TEAMCITY_VERSION` environment variable is set in your TeamCity build configuration. Without it, `teamcity-messages` might not auto-detect the TeamCity environment and report results.
fix
Ensure `TEAMCITY_VERSION` (any non-empty value) is present in the build environment where tests are run. TeamCity agents usually set this automatically.
affects: All versions
gotchaFor `unittest` integration, direct modification of the test runner in your test script (as shown in the quickstart) is generally required. Unlike some other frameworks, `unittest` doesn't automatically hook into `teamcity-messages` without explicit code.
fix
Implement the conditional `TeamcityTestRunner` usage in your `unittest.main()` block.
affects: All versions
gotchaTeamCity service messages are processed only when written to standard output (stdout). If your Python code or test runner redirects stdout or writes service messages to a file, TeamCity will not be able to parse them.
fix
Ensure service messages are printed directly to stdout. Avoid redirecting stdout when `teamcity-messages` is active in a TeamCity build step.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'teamcity_messages.unittestpy'
The top-level package for importing `teamcity-messages` components is `teamcity`, not `teamcity_messages`, despite the PyPI package name.
fix
from teamcity.unittestpy import TeamcityTestRunner
flake8: error: unrecognized arguments: --format=teamcity
The `teamcity-messages` plugin for Flake8 is not properly installed or detected, preventing it from recognizing the `--format=teamcity` option.
fix
Ensure `teamcity-messages` is installed in the same Python environment as Flake8: `pip install teamcity-messages`.
TypeError: testRunner must be an instance of TestRunner, not type
The `testRunner` argument in `unittest.main()` expects an *instance* of a test runner class, but the `TeamcityTestRunner` class itself was passed.
fix
Instantiate `TeamcityTestRunner` before passing it: `unittest.main(testRunner=TeamcityTestRunner())`.
AttributeError: type object 'TeamcityServiceMessages' has no attribute 'testStarted'
An attempt was made to call an instance method (`testStarted`) directly on the `TeamcityServiceMessages` class type instead of on an instantiated object.
fix
Create an instance of `TeamcityServiceMessages` first: `messages = TeamcityServiceMessages(output=sys.stdout); messages.testStarted('my_test')`.
pylint: error: No such reporter 'teamcity_pylint.PylintTeamcityReporter'
The `PylintTeamcityReporter` class, provided by `teamcity-messages`, cannot be found by Pylint because the library is not installed or accessible in the current Python environment.
fix
Install `teamcity-messages` in the same Python environment as Pylint: `pip install teamcity-messages`.
Upgrade
Version history
1.33latest on PyPI · released Jan 30, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
6
Resources