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. |
|
Module | Runs a Python module via the provided name (equally to adding |
|
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 |
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 |
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 |
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 |
Custom | Arguments of the Python interpreter (for example, If the step is launched in a virtual environment, these arguments are applied to the |
|
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. |
Install tool | Select this option to automatically install the selected tool package (Pytest, Flake8, or Pylint) if it is missing on the build agent. |
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 |
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:
Pipenv settings
Optionally, enter install run arguments.
Poetry settings
Optionally, enter install run arguments and a custom executable path to Poetry installed on a build agent.
The poetry install
command will be run for this environment tool. It will resolve dependencies specified in the pyproject.toml
file, located in the working directory. To be parsed correctly, this file should contain the tool.poetry
section.
Venv and virtualenv settings
Venv and virtualenv have the following settings:
Setting | Description |
---|---|
Requirement files | Path to the requirements file or a new-line separated list of files. |
Pip install run arguments | Additional arguments for the |
Environment name | Name of the virtual environment. |
Venv / virtualenv create arguments | Additional venv / virtualenv arguments to create a new |