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

To upload reports, you need your project’s Access Token. You can find this in your project settings on flakiness.io.

When the Access Token is provided, the reporter will upload the report to Flakiness.io in the end of the run. You will see a confirmation in your terminal:

PASSED [100%]
==============================
✅ [Flakiness] Report uploaded: https://flakiness.io/your_org/your_proj/run/1
==============================

Add your Flakiness.io access token to your repository:

  1. Navigate to your GitHub repository settings
  2. Go to Secrets and Variables → Actions
  3. Add a new secret named FLAKINESS_ACCESS_TOKEN
  4. Set its value to the access token from your Flakiness.io project settings
  5. Pass the secret as an environment variable to the npx playwright test step
# In your GitHub workflow file (.github/workflows/tests.yml)
jobs:
test:
runs-on: ubuntu-latest
steps:
# ... other steps like checkout, setup uv, etc.
- name: Run Pytest tests
env:
FLAKINESS_ACCESS_TOKEN: ${{ secrets.FLAKINESS_ACCESS_TOKEN }}
run: pytest

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 Tool:

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-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