Skip to main content
https://travis-ci.com/untitaker/pytest-sentry.svg?branch=master

pytest-sentry is a pytest plugin that sends error reports for flaky but ultimately not completely broken tests to Sentry.

What and Why

Let’s say you have a testsuite with some flaky tests that randomly break your CI build due to network issues, race conditions or other stuff that you don’t want to fix immediately. The known workaround is to retry those tests automatically, for example using pytest-rerunfailures.

One concern against plugins like this is that they just hide the bugs in your testsuite or even other code. After all your CI build is green and your code probably works most of the time.

pytest-sentry tries to make that choice a bit easier by tracking flaky test failures in a place separate from your build status. Sentry is already a good choice for keeping tabs on all kinds of errors, important or not, in production, so let’s try to use it in testsuites too.

How

The prerequisite is that you already make use of pytest and pytest-rerunfailures in CI. Now install pytest-sentry and set the PYTEST_SENTRY_DSN environment variable to the DSN of a new Sentry project.

Now every test failure that is “fixed” by retrying the test is reported to Sentry, but still does not break CI. Tests that consistently fail will not be reported.

Advanced Options

pytest-sentry supports marking your tests to use a different DSN, client or hub per-test. You can use this to provide custom options to the Client object from the Sentry SDK for Python:

import random
import pytest

from sentry_sdk import Hub
from pytest_sentry import Client

@pytest.mark.sentry_client(None)
def test_no_sentry():
    # Even though flaky, this test never gets reported to sentry
    assert random.random() > 0.5

@pytest.mark.sentry_client("MY NEW DSN")
def test_custom_dsn():
    # Use a different DSN to report errors for this one
    assert random.random() > 0.5

# Other invocations:

@pytest.mark.sentry_client(Client("CUSTOM DSN"))
@pytest.mark.sentry_client(lambda: Client("CUSTOM DSN"))
@pytest.mark.sentry_client(Hub(Client("CUSTOM DSN")))

The Client class exposed by pytest-sentry only has different default integrations. It disables some of the error-capturing integrations to avoid sending random expected errors into your project.

License

Licensed under MIT, see LICENSE.

Release files for pytest-sentry 0.1.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-sentry 0.1.0
File Size Uploaded
pytest-sentry-0.1.0.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-sentry 0.1.0
File Interpreter ABI Platform
pytest_sentry-0.1.0-py2-none-any.whl Python 2 none any Details

Total release size: 8.4 kB

Release files / pytest-sentry-0.1.0.tar.gz

Download URL pytest-sentry-0.1.0.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c772f8852cb2171cc3f41a795cf296a4be4cc4cb9ecf26717f469d325c44bb34
BLAKE2b-256 checksum
How to use checksums
4edd8876b4961bbccfd2f039d9a638ffaa7449e9d96c8b54204c90855ba73513
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release files / pytest_sentry-0.1.0-py2-none-any.whl

Download URL pytest_sentry-0.1.0-py2-none-any.whl
Size 4.8 kB
Tags Python 2
SHA-256 checksum
How to use checksums
f822a4aa5b05088133f651a1a48993d2418f374981e82a6f091474d406c8021d
BLAKE2b-256 checksum
How to use checksums
07e65d6f5cf242c49f96a6de233108c581ef798caf97116934e2f31d76ee33dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release history Release notifications | RSS feed

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

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