Python Unit Test Reporting to TeamCity
Clone or download
throwable-one Merge pull request #199 from JetBrains/link/198
#198 Anything may arrive from trial, do not assume it is regular exception
Latest commit c44f439 Dec 6, 2018


Python Unit Test Reporting to TeamCity

This package integrates Python with the TeamCity Continuous Integration (CI) server. It allows sending "service messages" from Python code. Additionally, it provides integration with the following testing frameworks and tools:


Install using pip:

pip install teamcity-messages

or from source:

python install


This package uses service messages to report the build status to TeamCity. See for more details


If you wish to use the Python default unittest framework, you should modify the Test runner, e.g.:

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()
        runner = unittest.TextTestRunner()

See examples/ for a full example.

If you are used to running unittest from the command line, instead of using python -m unittest, you could use python -m teamcity.unittestpy.


Test status reporting is enabled automatically under TeamCity build.


Test status reporting is enabled automatically under TeamCity build.


For Django 1.6+: Use the TeamcityDjangoRunner runner instead of the default DiscoverRunner by changing the following setting in your

TEST_RUNNER = "teamcity.django.TeamcityDjangoRunner"

If you are using another test runner, you should override the run_suite method or use the DiscoverRunner.test_runner property introduced in Django 1.7.


Test status reporting is enabled automatically under TeamCity build.


Pass TEAMCITY_VERSION environment variable inside your test virtenv. TEAMCITY_VERSION environment variable exists during build on Teamcity. teamcity-messages uses it in order to enable reporting to TeamCity.


Twisted trial

Add --reporter=teamcity option to trial command line


For Behave 1.2.6:

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

Python version compatibility

  • Python 2 - >= 2.6
  • Python 3 - >= 3.3
  • PyPy and PyPy 3
  • Jython

Contact information

TeamCity support:


Apache, version 2.0