Python Tests

Python Tests


Supported Python interpreters:

  • Python >= 2.7 and >= 3.5

Supported test frameworks:

  • pytest >= 3.0.0
    • pytest < 5 when using Python 2


Install the Datadog Agent to collect tests data.

Installing the Python tracer

Install the Python tracer by running:

pip install -U ddtrace

For more information, see the Python tracer installation documentation.

Instrumenting your tests

To enable instrumentation of pytest tests, add the --ddtrace option when running pytest, specifying the name of the service or library under test in the DD_SERVICE environment variable, and the environment where tests are being run (for example, local when running tests on a developer workstation, or ci when running them on a CI provider) in the DD_ENV environment variable:

DD_SERVICE=my-python-app DD_ENV=ci pytest --ddtrace

Configuration settings

The following is a list of the most important configuration settings that can be used with the tracer, either in code or using environment variables:

Name of the service or library under test.
Environment variable: DD_SERVICE
Default: pytest
Example: my-python-app
Name of the environment where tests are being run.
Environment variable: DD_ENV
Default: none
Examples: local, ci

The following environment variable can be used to configure the location of the Datadog Agent:

Datadog Agent URL for trace collection in the form http://hostname:port.
Default: http://localhost:8126

All other Datadog Tracer configuration options can also be used.

Further reading