Metadata-Version: 2.4
Name: testrelic-pytest
Version: 0.3.1
Summary: Generic pytest reporter that uploads test results to the TestRelic AI cloud platform.
Project-URL: Homepage, https://testrelic.ai
Project-URL: Documentation, https://docs.testrelic.ai/pytest
Project-URL: Repository, https://github.com/testrelic-ai/testrelic-python-sdk
Project-URL: Bug Tracker, https://github.com/testrelic-ai/testrelic-python-sdk/issues
Author-email: TestRelic AI <hello@testrelic.ai>
License: MIT
License-File: LICENSE
Keywords: analytics,ci,observability,pytest,reporter,test,test-automation,test-results,testing,testrelic
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.9
Requires-Dist: httpx<1.0,>=0.27
Requires-Dist: platformdirs>=4.0
Requires-Dist: pydantic<3.0,>=2.6
Requires-Dist: pytest>=7.0
Requires-Dist: tomli-w>=1.0
Requires-Dist: tomli>=2.0; python_version < '3.11'
Requires-Dist: typer<1.0,>=0.12
Provides-Extra: all
Requires-Dist: confluent-kafka>=2.3; extra == 'all'
Requires-Dist: gql>=3.5; extra == 'all'
Requires-Dist: grpcio-tools>=1.60; extra == 'all'
Requires-Dist: grpcio>=1.60; extra == 'all'
Requires-Dist: mcp>=1.0; extra == 'all'
Requires-Dist: websockets>=12.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest-xdist>=3.5; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: twine>=5.1; extra == 'dev'
Provides-Extra: graphql
Requires-Dist: gql>=3.5; extra == 'graphql'
Provides-Extra: grpc
Requires-Dist: grpcio-tools>=1.60; extra == 'grpc'
Requires-Dist: grpcio>=1.60; extra == 'grpc'
Provides-Extra: kafka
Requires-Dist: confluent-kafka>=2.3; extra == 'kafka'
Provides-Extra: mcp
Requires-Dist: mcp>=1.0; extra == 'mcp'
Provides-Extra: websocket
Requires-Dist: websockets>=12.0; extra == 'websocket'
Description-Content-Type: text/markdown

# testrelic-pytest

[![PyPI](https://img.shields.io/pypi/v/testrelic-pytest.svg)](https://pypi.org/project/testrelic-pytest/)

Generic [pytest](https://docs.pytest.org/) reporter that ships your test results
to the [TestRelic AI](https://testrelic.ai/) cloud platform. Works with any
pytest project — unit tests, API tests, integration tests — and stays out of the
way when no API key is configured.

## Install

```bash
pip install testrelic-pytest
```

The plugin auto-registers via the `pytest11` entry point. Nothing to import.

## Configure

```bash
export TESTRELIC_API_KEY=tr_live_...
pytest
```

The plugin silently no-ops when `TESTRELIC_API_KEY` is unset, so it is safe to
add to any project.

### Options

All options can be set via CLI flag, environment variable, or a JSON file at
`.testrelic/testrelic-config.json`. Precedence (highest first):
**CLI flag → environment → JSON file → defaults**.

CLI flags use a `--testrelic-pytest-*` prefix so they don't collide with the
`testrelic-playwright` plugin if both are installed.

| CLI flag | Env var | Default | Purpose |
|---|---|---|---|
| `--testrelic-pytest-disable` | `TESTRELIC_DISABLE=1` | off | Force-disable the plugin. |
| `--testrelic-pytest-api-key VALUE` | `TESTRELIC_API_KEY` | — | API key from the TestRelic dashboard. |
| `--testrelic-pytest-endpoint URL` | `TESTRELIC_CLOUD_ENDPOINT` | `https://platform.testrelic.ai/api/v1` | Cloud base URL. |
| `--testrelic-pytest-upload-strategy {batch,realtime,both,none}` | `TESTRELIC_UPLOAD_STRATEGY` | `batch` | When to send results. |
| `--testrelic-pytest-quiet` | `TESTRELIC_QUIET=1` | off | Suppress banner output. |
| `--testrelic-pytest-run-type {smoke,regression,nightly,ci}` | `TESTRELIC_RUN_TYPE` | — | Dashboard bucket. |
| `--testrelic-pytest-project-name NAME` | `TESTRELIC_PROJECT_NAME` | git remote or pyproject name | Stable project identity. |
| `--testrelic-pytest-artifact-threshold-kb N` | — | 32 | Captured output beyond N KB is truncated inline. |
| `--testrelic-pytest-output PATH` | — | — | Optional JSON dump for debugging. |

### Config file (`.testrelic/testrelic-config.json`)

```json
{
  "apiKey": "$TESTRELIC_API_KEY",
  "endpoint": "https://platform.testrelic.ai/api/v1",
  "upload": "batch",
  "projectName": "my-suite",
  "artifactThresholdKb": 32,
  "uploadArtifacts": true,
  "queueDirectory": ".testrelic/queue",
  "metadata": { "team": "platform" }
}
```

`$ENV_VAR` strings are expanded against the process environment at startup.

## What gets captured

For each test the plugin captures:

- `nodeId`, `file`, `className`, `testName`, `parametrizeId`
- Outcome: `passed | failed | skipped | xfailed | xpassed | error`
- Duration (ms) and per-phase breakdown (setup/call/teardown)
- Markers (e.g. `@pytest.mark.smoke`), keywords, parametrize ids
- Skip reasons and pytest warnings
- Failure tracebacks and assertion repr
- Captured stdout / stderr / caplog (inline with redaction; truncated above
  `--testrelic-artifact-threshold-kb`, hard cap 1 MB per stream — artifact
  upload for large streams is planned for v0.2)

Test runs include CI metadata auto-detected from GitHub Actions, GitLab CI,
Jenkins, and CircleCI, plus git branch/commit/author from the working tree.

## pytest-xdist

Parallel runs via `pytest-xdist` (`pytest -n 4`) are supported out of the box.
Each worker forwards its `TestReport` objects through the xdist channel; only
the controller node uploads. The result is exactly one cloud run with all tests
aggregated.

## Offline mode

Any upload that fails after retries is written to `~/.testrelic/queue/` as a
JSON file. Re-run later:

```bash
testrelic-pytest drain
```

The drainer re-authenticates with `TESTRELIC_API_KEY` and replays each entry to
its original endpoint.

## See also

- [`testrelic-deepeval`](https://pypi.org/project/testrelic-deepeval/) — DeepEval / LLM evaluation bridge
- [`testrelic-playwright`](https://pypi.org/project/testrelic-playwright/) — Playwright reporter for pytest
