TeamCity On-Premises 2020.2 Help

Python

The Python build runner automatically detects Python on agents and allows running Python scripts on Windows, Linux, and macOS.

Refer to Configuring Build Steps for a description of common build steps' settings. Refer to Docker Wrapper to learn how you can run this step inside a Docker container.

Сommand settings

You can choose one of the following Python commands:

Command

Description

Example input

File

Runs a Python script via the provided path.

scripts/test.py

Module

Runs a Python module via the provided name (equally to adding -m before the module name).

example-module

Custom script

Allows entering a Python script's body in the UI form.

ips = {} fh = open("/var/log/nginx/access.log", "r").readlines() for line in fh: ip = line.split(" ")[0] if 6 < len(ip) <=15: ips[ip] = ips.get(ip, 0) + 1 print ips

Unittest

Launch the unittest framework. The unit test results will be displayed on the Tests tab of Build Results.

To filter the scope of processed files, you can specify the path to unit test file(s) in the additional arguments.

Optionally, enter tests/*.py as an argument to launch all Python files in the tests directory via the unittest framework.

Pytest

Launch the pytest framework. The test results will be displayed on the Tests tab of Build Results.

To filter the scope of processed files, you can specify the path to pytest file(s) in the additional arguments.

Optionally, enter tests/*.py as an argument to launch all Python files in the tests directory via the pytest framework.

Flake8

Launch the Flake8 wrapper. The code inspection results will be displayed on the Code Inspection tab of Build Results.

To filter the scope of processed files, you can specify the path to Python file(s) in the additional arguments.

Optionally, enter docs/conf.py as an argument to check the conf.py file for errors.

Pylint

Launch the Pylint tool. The code inspection results will be displayed on the Code Inspection tab of Build Results.

To filter the scope of processed files, specify the path to Python file(s) in the additional arguments.

Enter scripts/*.py as an argument to check all Python files in the scripts directory for errors.

Custom

Arguments of the Python interpreter (for example, python3 arg1 arg2 ). Use this command if you want to enter a custom set of arguments.

If the step is launched in a virtual environment, these arguments are applied to the python command inside the environment (for example, python3 -m pipenv run python arg1 arg2 ).

arg1 arg2

The set of available settings depends on the selected command. This table describes all command settings:

Setting

Description

File

Path to a Python script file.

Module

Path to a Python module file.

Script or module arguments

Arguments that will be passed to the user script or module after their call.

Script

The custom script body.

Test reporting

Enables test reporting via the automatically installed teamcity-messages package. TeamCity receives test reports via service messages and displays them in the build log.

Coverage

Enable code coverage collecting via Coverage.py. TeamCity displays the produced test report on the Code Coverage tab.

Python arguments

Arguments that will be passed to the Python interpreter if a custom command is selected.

Python executable settings

In this block of settings, you can choose a Python version to run.

The Python runner automatically detects Python versions installed on a build agent. On Windows, it checks (1) the default install paths, (2) the system register, (3) the PATH variable. On Linux and macOS, it checks (1) the default install paths, (2) the PATH variable.

The runner sets the first detected versions of Python 2.x and 3.x as the agent's configuration parameters. Alternatively, you can provide a path to any installed version manually.

You can also specify arguments that will be passed to the interpreter in every Python run of this build step (for example, a custom environment tool run or reporting run).

Environment tool settings

Optionally, you can run a Python build step in a virtual environment. The Python runner supports the following tools:

If you choose Pipenv, enter additional install arguments if necessary.

Virtualenv has the following settings:

Setting

Description

Requirement files

Path to the requirements file or a new-line separated list of files.

Pip run arguments

Additional arguments for the pip run command.

Environment name

Name of the virtual environment.

Virtualenv arguments

Additional virtualenv arguments to create a new env command.

Last modified: 26 February 2021