88from sentry_sdk .transport import Transport
99from sentry_sdk .utils import Event , Dsn
1010
11+ class EventCaptured (Exception ):
12+ pass
13+
14+ class _TestTransport (Transport ):
15+ def __init__ (self , * a , ** kw ):
16+ pass
17+
18+ def start (self ):
19+ pass
20+
21+ def capture_event (self , event ):
22+ raise EventCaptured ()
23+
1124
1225def test_transport_option (monkeypatch ):
1326 dsn = "https://foo@sentry.io/123"
@@ -30,25 +43,18 @@ def e(exc_type):
3043 rv ._exc_value = exc_type ()
3144 return rv
3245
33- class EventCaptured (Exception ):
34- pass
35-
36- class TestTransport (Transport ):
37- def __init__ (self , * a , ** kw ):
38- pass
39-
40- def start (self ):
41- pass
42-
43- def capture_event (self , event ):
44- raise EventCaptured ()
45-
46- c = Client (ignore_errors = [Exception ], transport = TestTransport ())
46+ c = Client (ignore_errors = [Exception ], transport = _TestTransport ())
4747 c .capture_event (e (Exception ))
4848 c .capture_event (e (ValueError ))
4949 pytest .raises (EventCaptured , lambda : c .capture_event (e (BaseException )))
5050
5151
52+ def test_capture_event_works ():
53+ c = Client (transport = _TestTransport ())
54+ pytest .raises (EventCaptured , lambda : c .capture_event ({}))
55+ pytest .raises (EventCaptured , lambda : c .capture_event (Event ()))
56+
57+
5258@pytest .mark .parametrize ("num_messages" , [10 , 20 ])
5359def test_atexit (tmpdir , monkeypatch , num_messages ):
5460 app = tmpdir .join ("app.py" )
0 commit comments