{"id":5514,"library":"teamcity-messages","title":"TeamCity Messages","description":"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.","status":"active","version":"1.33","language":"en","source_language":"en","source_url":"https://github.com/JetBrains/teamcity-messages","tags":["TeamCity","CI","testing","pytest","unittest","nose","behave","coverage","flake8","pylint","JetBrains"],"install":[{"cmd":"pip install teamcity-messages","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Required to integrate with Python's standard unittest framework.","symbol":"TeamcityTestRunner","correct":"from teamcity.unittestpy import TeamcityTestRunner"},{"note":"Useful for conditionally enabling TeamCity reporting logic.","symbol":"is_running_under_teamcity","correct":"from teamcity import is_running_under_teamcity"},{"note":"For sending custom service messages directly to TeamCity.","symbol":"TeamcityServiceMessages","correct":"from teamcity.messages import TeamcityServiceMessages"}],"quickstart":{"code":"import unittest\nfrom teamcity import is_running_under_teamcity\nfrom teamcity.unittestpy import TeamcityTestRunner\nimport os\n\nclass MyTests(unittest.TestCase):\n    def test_success(self):\n        self.assertTrue(True, \"This test should pass\")\n\n    def test_failure(self):\n        self.assertEqual(1, 2, \"This test should fail\")\n\n    def test_skipped(self):\n        if os.environ.get('SKIP_TESTS') == '1':\n            self.skipTest(\"Skipping this test due to environment variable\")\n        self.assertTrue(True)\n\nif __name__ == '__main__':\n    print('Running tests...')\n    if is_running_under_teamcity():\n        print('Running under TeamCity, using TeamcityTestRunner')\n        runner = TeamcityTestRunner()\n    else:\n        print('Not running under TeamCity, using default TextTestRunner')\n        runner = unittest.TextTestRunner()\n    unittest.main(testRunner=runner, exit=False)","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to Python 3.6+ to use current versions of `teamcity-messages`.","message":"Older 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.","severity":"breaking","affected_versions":"<=1.27 for Python 2.6/3.5, <=1.25 for Python 3.4"},{"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.","message":"Compatibility 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.","severity":"gotcha","affected_versions":"All versions, as new tool versions are released."},{"fix":"Ensure `TEAMCITY_VERSION` (any non-empty value) is present in the build environment where tests are run. TeamCity agents usually set this automatically.","message":"For 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement the conditional `TeamcityTestRunner` usage in your `unittest.main()` block.","message":"For `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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure service messages are printed directly to stdout. Avoid redirecting stdout when `teamcity-messages` is active in a TeamCity build step.","message":"TeamCity 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}