Repository navigation
How to test functions with Sentry logging? #4499
Replies: 1 comment
|
Hi @jenstroeger, there is a supported way to do this — you don't need the deprecated hack from Stack Overflow. The intended mechanism is a custom transport. Sentry's own docs for the import sentry_sdk
from sentry_sdk.transport import Transport
captured = []
class RecordingTransport(Transport):
def capture_envelope(self, envelope):
captured.append(envelope)
return None
sentry_sdk.init(transport=RecordingTransport())
# ... exercise your code, then assert on `captured`A simpler alternative if you only need error events (not envelopes/transactions) is a One gotcha worth knowing: an exception raised at a bare REPL prompt isn't captured by the SDK — call There's also a community pytest plugin, |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
Some of my code under test sends data to Sentry. However, when run under pytest I’d like to capture that data instead of sending it off. I found this hack but it builds on deprecated Sentry code. Couldn’t find any mention of testing in the docs either 🤔
Question: how do I go about unit-testing code that sends data to Sentry?
Cheers!
All reactions