Python collectors
To use Buildkite Test Engine with your Python projects, use the buildkite-test-collector package with pytest.
The recommended way to set up a new test suite is to add the Tests Buildkite plugin to the step that runs your tests. It works with every runner that bktec supports, and the entire setup is configuration-only. You can get a test suite running through changes to pipeline.yml alone, with no modifications to your application code.
Use the language-specific test collector documented on this page when you want deeper framework integration, such as custom execution tags, span annotations, or richer per-framework data. For a runner that bktec supports, you can use bktec to run and split tests while the collector uploads the results. To prevent duplicate test executions, set BUILDKITE_TEST_ENGINE_UPLOAD_RESULTS to false. If you use the Tests Buildkite plugin, set upload-results: false.
You can also upload test results by importing JSON or JUnit XML.
Tests Buildkite plugin example for pytest
The following step uses the Tests Buildkite plugin to run a pytest suite through bktec. The plugin downloads bktec, requests an OIDC token, ensures the test suite exists, and exports the environment variables that bktec expects, so the step's command only needs to invoke bktec run:
steps:
- label: "pytest"
command: bktec run
plugins:
- tests#v1.0.0:
test-runner: pytest
parallelism: 4
See the Tests Buildkite plugin page for the full plugin reference, including all supported options and dynamic parallelism with bktec plan.
pytest collector
pytest is a testing framework for Python.
If you're already using pytest, then you can install buildkite-test-collector to collect test results into your Test Engine dashboard.
Before you start, make sure pytest runs with access to CI environment variables.
To get started with buildkite-test-collector:
In your CI environment, set the
BUILDKITE_ANALYTICS_TOKENenvironment variable securely to your Buildkite Test Engine API token.-
Add
buildkite-test-collectorto your list of dependencies. Some examples:-
If you're using a
requirements.txtfile, addbuildkite-test-collectoron a new line. -
If you're using a
setup.pyfile, addbuildkite-test-collectorto theextras_requireargument, like this:extras_require={"dev": ["pytest", "buildkite-test-collector"]} -
If you're using Pipenv, run
pipenv install --dev buildkite-test-collector.
If you're using another tool, see your dependency management system's documentation for help.
-
-
Commit and push your changes:
$ git add . $ git commit -m "Install and set up Buildkite Test Engine" $ git push
Once you're done, in your Test Engine dashboard, you'll see analytics of test executions on all branches that include this code.
If you don't see branch names, build numbers, or commit hashes in Test Engine, then read CI environments to learn more about exporting your environment to the collector.
Collecting pytest tests with OpenTelemetry
The Python collector can send pytest results to Buildkite Test Engine as OpenTelemetry spans. Each test execution becomes a root span. Optional child spans show operations inside the test, such as HTTP requests and database queries.
Use Python 3.10 or later, pytest 7 or later, and buildkite-test-collector version 1.10.0 or higher. OpenTelemetry collection is disabled by default. This integration supports suites that do not already configure OpenTelemetry.
Create a test suite if you do not have one. Configure OIDC authentication, or store your suite API token securely as
BUILDKITE_ANALYTICS_TOKENin the environment that runs pytest.-
Install the collector with its optional OpenTelemetry dependencies:
python -m pip install "buildkite-test-collector[otel]>=1.10.0"The
otelextra installs the OpenTelemetry SDK and HTTP/protobuf exporter, both version 1.45 or later. -
Enable OpenTelemetry collection and run pytest with its token and CI environment variables available:
export BUILDKITE_ANALYTICS_OTEL_ENABLED=true pytestThe collector registers automatically as a pytest plugin. No changes to
conftest.pyare needed to collect test results. To return to JSON uploads, unsetBUILDKITE_ANALYTICS_OTEL_ENABLED. Open the new run in your Buildkite Test Engine suite. For upload problems, check the collector's warnings and the suite's Uploads page.
OpenTelemetry spans replace JSON uploads. Do not also upload the same executions using bktec or another upload method.
See the collector's OpenTelemetry guide for child span instrumentation, configuration options, and troubleshooting.