Skip to main content

pytest-charisma

A pytest plugin that streams test results to the Charisma ingestion API as tests execute.

Results are batched and sent in a background thread so test execution is not blocked by network I/O. The plugin implements retry-once semantics and a circuit breaker (3 consecutive failures disables streaming for the rest of the session).

Installation

pip install pytest-charisma

No token, no index URL — works on any laptop and in any CI. The package is published to public PyPI; the Charisma repo itself stays private (only this client plugin wheel is public).

For local development from a checkout of the repo:

pip install -e packages/pytest-charisma

Publishing (maintainers)

Releases publish to public PyPI automatically from the merge-queue workflow using a PyPI API token.

Trusted publishing (OIDC) is not used because this repo runs on GitHub Enterprise Server, whose OIDC issuer PyPI does not trust. A stored API token is required instead.

One-time setup (done once by a PyPI project owner):

  1. Sign in to PyPI with the team-owned account (2FA enabled).
  2. Go to Account settings → API tokens → Add API token. Scope it to the pytest-charisma project once the project exists; for the very first publish use an account-scoped token, then re-scope it to the project afterward.
  3. Copy the token (starts with pypi-).
  4. In the GitHub Enterprise repo, add it as an Actions secret named PYPI_API_TOKEN (org-level secret recommended so both packages share it).
  5. Bump version in pyproject.toml and merge — the workflow builds and publishes on the next release.

Rotate the token periodically and store it in the team secret manager.


Quick start

pytest \
  --charisma-url https://api.charisma.example.com \
  --charisma-token $CHARISMA_TOKEN \
  --charisma-project-alias my-project

The plugin activates automatically when charisma_url is configured. If the URL is absent, the plugin stays silent and does nothing.

Configuration

Options are resolved with priority: CLI flag > pytest.ini / pyproject.toml > environment variable.

CLI flag ini key Env var Required Description
--charisma-url charisma_url CHARISMA_URL Yes API base URL
--charisma-token charisma_token CHARISMA_TOKEN Yes Bearer token for authentication
--charisma-project-alias charisma_project_alias CHARISMA_PROJECT_ALIAS Yes Project alias in Charisma
--charisma-batch-size charisma_batch_size CHARISMA_BATCH_SIZE No Results per batch, 1–50 (default: 20)
--charisma-build-id charisma_build_id CHARISMA_BUILD_ID No CI build number or identifier
--charisma-commit-sha charisma_commit_sha CHARISMA_COMMIT_SHA No Git commit SHA
--charisma-branch charisma_branch CHARISMA_BRANCH No Git branch name
--charisma-component charisma_component CHARISMA_COMPONENT No Component alias within the project
--charisma-source-url charisma_source_url CHARISMA_SOURCE_URL No Link back to CI/CD run

Configuration via pyproject.toml

[tool.pytest.ini_options]
charisma_url = "https://api.charisma.example.com"
charisma_project_alias = "my-project"
charisma_batch_size = "10"
charisma_branch = "main"
# Token should come from env var for security:
# export CHARISMA_TOKEN=your-token

Configuration via pytest.ini

[pytest]
charisma_url = https://api.charisma.example.com
charisma_project_alias = my-project
charisma_batch_size = 10

Environment variables only (CI-friendly)

export CHARISMA_URL=https://api.charisma.example.com
export CHARISMA_TOKEN=your-api-token
export CHARISMA_PROJECT_ALIAS=my-project
export CHARISMA_BUILD_ID=$CI_BUILD_NUMBER
export CHARISMA_COMMIT_SHA=$CI_COMMIT_SHA
export CHARISMA_BRANCH=$CI_BRANCH
export CHARISMA_SOURCE_URL=$CI_BUILD_URL

pytest

How it works

  1. Collection — After pytest collects tests, the plugin opens a launch session via POST /api/v1/launches.
  2. Execution — As each test completes, results are buffered. When the buffer reaches batch_size, the batch is submitted to a background worker thread.
  3. Flush — At session end, remaining results are flushed and the worker drains its queue (up to 30s timeout).
  4. Resilience — Each batch gets one retry on failure. After 3 consecutive batch failures, the circuit breaker trips and streaming is disabled for the rest of the session. Test execution is never affected.

Outcome mapping

pytest outcome Charisma status
passed (call phase) passed
failed (call phase) failed
skipped skipped
failed (setup/teardown) broken

Requirements

  • Python ≥ 3.10
  • pytest ≥ 7.0, < 9.0
  • httpx ≥ 0.24, < 1.0

Development

cd packages/pytest-charisma
pip install -e ".[dev]"
pytest

License

MIT

Release files for pytest-charisma 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-charisma 0.4.0
File Size Uploaded
pytest_charisma-0.4.0.tar.gz 41.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-charisma 0.4.0
File Interpreter ABI Platform
pytest_charisma-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 58.1 kB

Release files / pytest_charisma-0.4.0.tar.gz

Download URL pytest_charisma-0.4.0.tar.gz
Size 41.4 kB
Tags Source
SHA-256 checksum
How to use checksums
71db5a9b557d4e1d4f3120d5b2d0cc221c6f75f63e3fce09e6c3beef5eb2c6e0
BLAKE2b-256 checksum
How to use checksums
60599ca74fb54e8d054eebd7e68939d2f6fff7e2de280b0007e61f631ff1972a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / pytest_charisma-0.4.0-py3-none-any.whl

Download URL pytest_charisma-0.4.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76420d23f7ea72071f6a0f8efb3c1c5b4bdcba8e8346ca62045378b7f8c63260
BLAKE2b-256 checksum
How to use checksums
cdecbfbec85400cd1340b956ebf741d88d25501d8e03fc0cd606465bd0d4ea73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page