Skip to content

Pytest

The official Flakiness.io reporter for pytest.

  1. Install using uv (recommended):

    Terminal window
    uv add --dev pytest-flakiness

    Or via standard pip:

    Terminal window
    pip install pytest-flakiness

Reports are automatically uploaded to Flakiness.io at the end of each test run when authentication is configured. If no credentials are present, the report is still generated locally and can be uploaded manually later.

When uploading succeeds, you’ll see a confirmation in your terminal:

PASSED [100%]
==============================
[Flakiness] Report uploaded: https://flakiness.io/your_org/your_proj/run/1
==============================
Upload MethodStatusGuide
GitHub OIDC v0.13.0+SupportedGitHub Actions
Access TokenSupportedGitHub Actions
Other CISupportedOther CI Providers

Once installed, simply run pytest. The reporter will automatically activate, aggregate test results, and create Flakiness Report in the flakiness-report directory.

Terminal window
pytest

The generated report can be viewed interactively via the Flakiness CLI:

Terminal window
flakiness show

All options can be set via environment variables or command-line flags:

FlagEnvironment VariableDescription
--flakiness-nameFLAKINESS_NAMEName for this environment. Defaults to pytest
--flakiness-output-dirFLAKINESS_OUTPUT_DIRLocal directory to save JSON report. Defaults to flakiness-report
--flakiness-projectFLAKINESS_PROJECTYour Flakiness.io project in orgSlug/projectSlug format (required for GitHub OIDC)
--flakiness-access-tokenFLAKINESS_ACCESS_TOKENYour Flakiness.io access token (required for upload)
--flakiness-endpointFLAKINESS_ENDPOINTFlakiness.io service endpoint. Defaults to https://flakiness.io

You can add custom metadata to your test runs using FK_ENV_* environment variables:

Terminal window
export FK_ENV_GPU_TYPE="H100"
export FK_ENV_DEPLOYMENT="staging"
pytest

The FK_ENV_ prefix is removed and keys are lowercased, e.g. FK_ENV_DEPLOYMENT becomes deployment, and FK_ENV_GPU_TYPE becomes gpu_type.

The source code is available under MIT license at https://github.com/flakiness/pytest-flakiness