CI Visibility is not available in the selected site () at this time.
Python test instrumentation is in beta.
Supported Python interpreters:
Python >= 2.7 and >= 3.5
Supported test frameworks:
pytest >= 3.0.0
pytest < 5 when using Python 2
Installing the Datadog Agent
To report test results to Datadog, you need to install the Datadog Agent.
Using an on-premises CI provider
If you are running tests on an on-premises CI provider, such as Jenkins or self-managed GitLab CI, install the Datadog Agent on each worker node by following the Agent installation instructions.
If the CI provider is using a container-based executor, set the DD_AGENT_HOST environment variable on all builds (which defaults to http://localhost:8126) to an endpoint that is accessible from within build containers, as using localhost inside the build references the container itself and not the underlying worker node where the Datadog Agent is running.
If you are using a Kubernetes executor, Datadog recommends using the Datadog Admission Controller, which automatically sets the DD_AGENT_HOST environment variable in the build pods to communicate with the local Datadog Agent.
Using a cloud CI provider
If you are using a cloud CI provider with no access to the underlying worker nodes, such as GitHub Actions or CircleCI, run the Datadog Agent in a container as a build service. This method is also available for an on-premises CI provider that uses a container-based executor if installing the Datadog Agent on each worker node is not an option.
To run the Datadog Agent as a container acting as a simple results forwarder, use the Docker image gcr.io/datadoghq/agent:latest and the following environment variables:
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:
You can add custom tags to your tests by using the declaring ddspan as argument to your test:
fromddtraceimporttracer# Declare `ddspan` as argument to your testdeftest_simple_case(ddspan):# Set your tagsddspan.set_tag("test_owner","my_team")# test continues normally# ...
To create filters or group by fields for these tags, you must first create facets. For more information about adding tags, see the Adding Tags section of the Python custom instrumentation documentation.
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
Datadog uses Git information for visualizing your test results and grouping them by repository, branch, and commit. Git metadata is automatically collected by the test instrumentation from CI provider environment variables and the local .git folder in the project path, if available.
If you are running tests in non-supported CI providers or with no .git folder, you can set the Git information manually using environment variables. These environment variables take precedence over any auto-detected information. Set the following environment variables to provide Git information:
URL of the repository where the code is stored. Both HTTP and SSH URLs are supported. Example: firstname.lastname@example.org:MyCompany/MyApp.git, https://github.com/MyCompany/MyApp.git
Git branch being tested. Leave empty if providing tag information instead. Example: develop
Git tag being tested (if applicable). Leave empty if providing branch information instead. Example: 1.0.1
Full commit hash. Example: a18ebf361cc831f5535e58ec4fae04ffd98d8152
Commit message. Example: Set release number
Commit author name. Example: John Smith
Commit author email. Example: email@example.com
Commit author date in ISO 8601 format. Example: 2021-03-12T16:00:28Z
Commit committer name. Example: Jane Smith
Commit committer email. Example: firstname.lastname@example.org
Commit committer date in ISO 8601 format. Example: 2021-03-12T16:00:28Z
When CI Visibility is enabled, the following data is collected from your project:
Test names and durations.
Predefined environment variables set by CI providers.
Git commit history including the hash, message, author information, and files changed (without file contents).
Information from the CODEOWNERS file.
Additional helpful documentation, links, and articles: