Skip to main content

pytest-sentry-capture

Capture and inspect Sentry events in pytest without sending them over the network. Requires Python 3.12 or newer.

pip install pytest-sentry-capture

Pytest discovers the plugin automatically. Do not also add it to pytest_plugins. The plugin does not initialize Sentry until a fixture is requested.

import sentry_sdk
import pytest_sentry_capture as capture


def test_error(sentry_capture: capture.SentryCapture) -> None:
    sentry_sdk.add_breadcrumb(message="starting", level="info")
    sentry_sdk.capture_message("hello")

    event = next(sentry_capture.get_events())
    assert event["message"] == "hello"
    assert sentry_capture.find_breadcrumb_by_message("starting")["level"] == "info"

Fixtures and inspection

  • sentry_capture: isolated client with in-memory transport and full transaction sampling; yields a SentryCapture.
  • sentry_transport: a FakeTransport you can inject into application setup.
  • sentry_isolation_scope: an isolated, blank client for tests that own SDK setup.

Use get_events, get_transactions, get_spans, get_breadcrumbs, and get_exceptions to iterate captured data. Reads flush the active client and do not consume captured envelopes. The find_* methods return the first match or raise LookupError. Each test receives fresh envelopes.

Fixture teardown closes its own client inside the isolated scope and restores the enclosing scope. If application code creates another client, it owns that client's cleanup. These fixtures isolate the SDK scope, not process-global logging handlers or arbitrary framework instrumentation. Use xdist for process-level parallelism; concurrent SDK reconfiguration within a worker is unsupported.

Development

nix develop
pytest -q
basedpyright
nix fmt
nix flake check
nix build

uv.lock fixes the development environment. Published dependency ranges are separate compatibility contracts. See RELEASING.md for repository setup and PyPI trusted publishing.

License

Licensed under the Apache License 2.0.

Metadata

Release files for pytest-sentry-capture 0.1.1

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-sentry-capture 0.1.1
File Size Uploaded Provenance
pytest_sentry_capture-0.1.1.tar.gz 50.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-sentry-capture 0.1.1
File Interpreter ABI Platform
pytest_sentry_capture-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 59.2 kB

Release files / pytest_sentry_capture-0.1.1.tar.gz

Download URL pytest_sentry_capture-0.1.1.tar.gz
Size 50.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6c63e9d161397334124291131389b71353ce0807be6cefe1698b2f29e90865ca
BLAKE2b-256 checksum
How to use checksums
33f56773e102e2e136b7e7e93c76e0ed3f3899960105ac888bf10b6705b034b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / pytest_sentry_capture-0.1.1-py3-none-any.whl

Download URL pytest_sentry_capture-0.1.1-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41fe3956a8b047523c80f2c8debbf8b18adde8e65d3fceb50ab8f76ef0874405
BLAKE2b-256 checksum
How to use checksums
b793f1902b854fdf74a62e86fe3015036049647ab66e720f7425f77b84b09be7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Security for pytest-sentry-capture 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_sentry_capture-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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