TeamCity Messages

1.33 · active · verified Mon Apr 13

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.

Warnings

Install

Imports

Quickstart

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)

view raw JSON →