pytest with GitHub Actions
Write a JUnit XML report with pytest, send it to Kollaudo, and gate a staging promotion on the verdict. See Sending test results for tokens and exit codes.
1. Write the report
Section titled “1. Write the report”No reporting plugin is needed for JUnit XML:
pytest --junitxml=junit.xmlAlternatively, install pytest-json-ctrf and run pytest --ctrf ctrf-report.json for CTRF.
The CLI reads either format; --tool pytest identifies the producer of a JUnit report.
The repository tests the parser with a real pytest report.
2. Send unit or environment-level results
Section titled “2. Send unit or environment-level results”Install @kollaudo/cli with Node.js 24 or newer, then configure KOLLAUDO_URL and an
ingest KOLLAUDO_TOKEN. Keep tokens in your CI secret store.
Unit tests belong to the build, not a deployed environment:
kollaudo push junit.xml --tool pytest --component api --version "$VERSION" --kind unitTests against staging include the environment:
kollaudo push junit.xml --tool pytest --component api --version "$VERSION" --env staging --kind e2eSend the report even when pytest fails. push returning zero means the report was stored,
not that the tests passed. Build-level unit results are shown in Kollaudo but do not count
towards the staging verdict; do not gate them with --env staging --require unit.
Retries need evidence in the report. Kollaudo marks a test flaky when its report preserves a
failed attempt followed by a pass, or supplies CTRF flaky/retries fields. However, plain
pytest JUnit output can keep only the final outcome after pytest-rerunfailures: even the
checked-in fixture’s test_flaky_search is parsed as an ordinary pass. Enabling retries
alone does not guarantee a flaky marker; check the reporter’s output before relying on it.
3. Gate a staging promotion
Section titled “3. Gate a staging promotion”The example assumes staging already runs $VERSION and your pytest suite targets it
through BASE_URL. Adjust that variable to your test project’s configuration. Store
KOLLAUDO_URL as a repository variable and KOLLAUDO_TOKEN as a secret.
env: KOLLAUDO_URL: ${{ vars.KOLLAUDO_URL }} KOLLAUDO_TOKEN: ${{ secrets.KOLLAUDO_TOKEN }} VERSION: ${{ github.sha }}
jobs: test-staging: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - uses: actions/setup-python@v7 with: python-version: "3.12" - uses: actions/setup-node@v7 with: node-version: 24 - run: python -m pip install -r requirements.txt pytest - run: npm install --global @kollaudo/cli@0.5.0 - run: pytest --junitxml=junit.xml env: BASE_URL: https://staging.example.com - name: Send the results even when tests fail if: ${{ !cancelled() }} run: >- kollaudo push junit.xml --tool pytest --component api --version "$VERSION" --env staging --kind e2e
promote: needs: test-staging if: ${{ !cancelled() }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - uses: kollaudo/action@v0 with: url: ${{ vars.KOLLAUDO_URL }} token: ${{ secrets.KOLLAUDO_GATE_TOKEN }} component: api environment: staging version: ${{ env.VERSION }} require: e2e - run: ./deploy.sh production "$VERSION"The promotion job asks for the verdict even if pytest failed, with the
Kollaudo gate action: it fails the job unless
the verdict is pass. require: e2e also prevents a missing report from being mistaken for a pass.
Give the gate its own read token, KOLLAUDO_GATE_TOKEN, so that Kollaudo’s log of verdicts says
which gate asked. Policies can impose additional requirements; keep the same component, environment
and version throughout.
Outside GitHub Actions, the same gate is
kollaudo verdict --component api --env staging --version "$VERSION" --require e2e. It exits with 0
(pass), 1 (fail), 2 (unknown evidence) and 3 (connection, token or option error).