1818
1919
2020@pytest .fixture
21- def app (sentry_init ):
22- sentry_init (
23- integrations = [
24- flask_sentry .FlaskIntegration (),
25- LoggingIntegration (event_level = "ERROR" ),
26- ]
27- )
28-
21+ def app ():
2922 app = Flask (__name__ )
3023 app .config ["TESTING" ] = True
3124 app .secret_key = "haha"
@@ -40,7 +33,8 @@ def hi():
4033 return app
4134
4235
43- def test_has_context (app , capture_events ):
36+ def test_has_context (sentry_init , app , capture_events ):
37+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
4438 events = capture_events ()
4539
4640 client = app .test_client ()
@@ -55,7 +49,9 @@ def test_has_context(app, capture_events):
5549
5650@pytest .mark .parametrize ("debug" , (True , False ))
5751@pytest .mark .parametrize ("testing" , (True , False ))
58- def test_errors (capture_exceptions , app , debug , testing ):
52+ def test_errors (sentry_init , capture_exceptions , app , debug , testing ):
53+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
54+
5955 app .debug = debug
6056 app .testing = testing
6157
@@ -75,7 +71,9 @@ def index():
7571 assert isinstance (exc , ZeroDivisionError )
7672
7773
78- def test_flask_login_not_installed (app , capture_events , monkeypatch ):
74+ def test_flask_login_not_installed (sentry_init , app , capture_events , monkeypatch ):
75+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
76+
7977 monkeypatch .setattr (flask_sentry , "current_user" , None )
8078
8179 events = capture_events ()
@@ -87,7 +85,9 @@ def test_flask_login_not_installed(app, capture_events, monkeypatch):
8785 assert event .get ("user" , {}).get ("id" ) is None
8886
8987
90- def test_flask_login_not_configured (app , capture_events , monkeypatch ):
88+ def test_flask_login_not_configured (sentry_init , app , capture_events , monkeypatch ):
89+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
90+
9191 assert flask_sentry .current_user is not None
9292
9393 events = capture_events ()
@@ -98,7 +98,11 @@ def test_flask_login_not_configured(app, capture_events, monkeypatch):
9898 assert event .get ("user" , {}).get ("id" ) is None
9999
100100
101- def test_flask_login_partially_configured (app , capture_events , monkeypatch ):
101+ def test_flask_login_partially_configured (
102+ sentry_init , app , capture_events , monkeypatch
103+ ):
104+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
105+
102106 events = capture_events ()
103107
104108 login_manager = LoginManager ()
@@ -112,7 +116,9 @@ def test_flask_login_partially_configured(app, capture_events, monkeypatch):
112116
113117
114118@pytest .mark .parametrize ("user_id" , [None , "42" , 3 ])
115- def test_flask_login_configured (app , user_id , capture_events , monkeypatch ):
119+ def test_flask_login_configured (sentry_init , app , user_id , capture_events , monkeypatch ):
120+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
121+
116122 class User (object ):
117123 is_authenticated = is_active = True
118124 is_anonymous = user_id is not None
@@ -146,7 +152,9 @@ def login():
146152 assert event ["user" ]["id" ] == str (user_id )
147153
148154
149- def test_flask_large_json_request (capture_events , app ):
155+ def test_flask_large_json_request (sentry_init , capture_events , app ):
156+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
157+
150158 data = {"foo" : {"bar" : "a" * 2000 }}
151159
152160 @app .route ("/" , methods = ["POST" ])
@@ -171,7 +179,9 @@ def index():
171179 assert event ["request" ]["data_info" ] == {"ct" : "json" , "repr" : "structured" }
172180
173181
174- def test_flask_large_formdata_request (capture_events , app ):
182+ def test_flask_large_formdata_request (sentry_init , capture_events , app ):
183+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
184+
175185 data = {"foo" : "a" * 2000 }
176186
177187 @app .route ("/" , methods = ["POST" ])
@@ -197,7 +207,9 @@ def index():
197207
198208
199209@pytest .mark .parametrize ("input_char" , [u"a" , b"a" ])
200- def test_flask_large_text_request (input_char , capture_events , app ):
210+ def test_flask_large_text_request (sentry_init , input_char , capture_events , app ):
211+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
212+
201213 data = input_char * 2000
202214
203215 @app .route ("/" , methods = ["POST" ])
@@ -225,7 +237,9 @@ def index():
225237 assert event ["request" ]["data_info" ] == {"ct" : "plain" , "repr" : "other" }
226238
227239
228- def test_flask_large_bytes_request (capture_events , app ):
240+ def test_flask_large_bytes_request (sentry_init , capture_events , app ):
241+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
242+
229243 data = b"\xc3 " * 2000
230244
231245 @app .route ("/" , methods = ["POST" ])
@@ -250,7 +264,9 @@ def index():
250264 assert event ["request" ]["data_info" ] == {"ct" : "bytes" , "repr" : "base64" }
251265
252266
253- def test_flask_files_and_form (capture_events , app ):
267+ def test_flask_files_and_form (sentry_init , capture_events , app ):
268+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
269+
254270 data = {"foo" : "a" * 2000 , "file" : (BytesIO (b"hello" ), "hello.txt" )}
255271
256272 @app .route ("/" , methods = ["POST" ])
@@ -279,7 +295,16 @@ def index():
279295 assert not event ["request" ]["data" ]["file" ]
280296
281297
282- def test_errors_not_reported_twice (capture_events , app ):
298+ @pytest .mark .parametrize (
299+ "integrations" ,
300+ [
301+ [flask_sentry .FlaskIntegration ()],
302+ [flask_sentry .FlaskIntegration (), LoggingIntegration (event_level = "ERROR" )],
303+ ],
304+ )
305+ def test_errors_not_reported_twice (sentry_init , integrations , capture_events , app ):
306+ sentry_init (integrations = integrations )
307+
283308 @app .route ("/" )
284309 def index ():
285310 try :
@@ -297,8 +322,14 @@ def index():
297322 assert len (events ) == 1
298323
299324
300- def test_logging (capture_events , app ):
325+ def test_logging (sentry_init , capture_events , app ):
301326 # ensure that Flask's logger magic doesn't break ours
327+ sentry_init (
328+ integrations = [
329+ flask_sentry .FlaskIntegration (),
330+ LoggingIntegration (event_level = "ERROR" ),
331+ ]
332+ )
302333
303334 @app .route ("/" )
304335 def index ():
0 commit comments