Skip to content

Commit 4b41f91

Browse files
committed
fix quart
1 parent 806992f commit 4b41f91

File tree

1 file changed

+46
-28
lines changed

1 file changed

+46
-28
lines changed

tests/integrations/quart/test_quart.py

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import json
22
import threading
3+
from unittest import mock
34

45
import pytest
5-
import pytest_asyncio
66

77
import sentry_sdk
88
from sentry_sdk import (
@@ -28,8 +28,7 @@
2828
auth_manager = AuthManager()
2929

3030

31-
@pytest_asyncio.fixture
32-
async def app():
31+
def quart_app_factory():
3332
app = Quart(__name__)
3433
app.debug = False
3534
app.config["TESTING"] = False
@@ -73,8 +72,9 @@ def integration_enabled_params(request):
7372

7473

7574
@pytest.mark.asyncio
76-
async def test_has_context(sentry_init, app, capture_events):
75+
async def test_has_context(sentry_init, capture_events):
7776
sentry_init(integrations=[quart_sentry.QuartIntegration()])
77+
app = quart_app_factory()
7878
events = capture_events()
7979

8080
client = app.test_client()
@@ -99,7 +99,6 @@ async def test_has_context(sentry_init, app, capture_events):
9999
)
100100
async def test_transaction_style(
101101
sentry_init,
102-
app,
103102
capture_events,
104103
url,
105104
transaction_style,
@@ -111,6 +110,7 @@ async def test_transaction_style(
111110
quart_sentry.QuartIntegration(transaction_style=transaction_style)
112111
]
113112
)
113+
app = quart_app_factory()
114114
events = capture_events()
115115

116116
client = app.test_client()
@@ -126,10 +126,10 @@ async def test_errors(
126126
sentry_init,
127127
capture_exceptions,
128128
capture_events,
129-
app,
130129
integration_enabled_params,
131130
):
132131
sentry_init(**integration_enabled_params)
132+
app = quart_app_factory()
133133

134134
@app.route("/")
135135
async def index():
@@ -153,9 +153,10 @@ async def index():
153153

154154
@pytest.mark.asyncio
155155
async def test_quart_auth_not_installed(
156-
sentry_init, app, capture_events, monkeypatch, integration_enabled_params
156+
sentry_init, capture_events, monkeypatch, integration_enabled_params
157157
):
158158
sentry_init(**integration_enabled_params)
159+
app = quart_app_factory()
159160

160161
monkeypatch.setattr(quart_sentry, "quart_auth", None)
161162

@@ -170,9 +171,10 @@ async def test_quart_auth_not_installed(
170171

171172
@pytest.mark.asyncio
172173
async def test_quart_auth_not_configured(
173-
sentry_init, app, capture_events, monkeypatch, integration_enabled_params
174+
sentry_init, capture_events, monkeypatch, integration_enabled_params
174175
):
175176
sentry_init(**integration_enabled_params)
177+
app = quart_app_factory()
176178

177179
assert quart_sentry.quart_auth
178180

@@ -186,9 +188,10 @@ async def test_quart_auth_not_configured(
186188

187189
@pytest.mark.asyncio
188190
async def test_quart_auth_partially_configured(
189-
sentry_init, app, capture_events, monkeypatch, integration_enabled_params
191+
sentry_init, capture_events, monkeypatch, integration_enabled_params
190192
):
191193
sentry_init(**integration_enabled_params)
194+
app = quart_app_factory()
192195

193196
events = capture_events()
194197

@@ -205,13 +208,13 @@ async def test_quart_auth_partially_configured(
205208
async def test_quart_auth_configured(
206209
send_default_pii,
207210
sentry_init,
208-
app,
209211
user_id,
210212
capture_events,
211213
monkeypatch,
212214
integration_enabled_params,
213215
):
214216
sentry_init(send_default_pii=send_default_pii, **integration_enabled_params)
217+
app = quart_app_factory()
215218

216219
@app.route("/login")
217220
async def login():
@@ -242,10 +245,9 @@ async def login():
242245
[quart_sentry.QuartIntegration(), LoggingIntegration(event_level="ERROR")],
243246
],
244247
)
245-
async def test_errors_not_reported_twice(
246-
sentry_init, integrations, capture_events, app
247-
):
248+
async def test_errors_not_reported_twice(sentry_init, integrations, capture_events):
248249
sentry_init(integrations=integrations)
250+
app = quart_app_factory()
249251

250252
@app.route("/")
251253
async def index():
@@ -265,14 +267,15 @@ async def index():
265267

266268

267269
@pytest.mark.asyncio
268-
async def test_logging(sentry_init, capture_events, app):
270+
async def test_logging(sentry_init, capture_events):
269271
# ensure that Quart's logger magic doesn't break ours
270272
sentry_init(
271273
integrations=[
272274
quart_sentry.QuartIntegration(),
273275
LoggingIntegration(event_level="ERROR"),
274276
]
275277
)
278+
app = quart_app_factory()
276279

277280
@app.route("/")
278281
async def index():
@@ -289,13 +292,17 @@ async def index():
289292

290293

291294
@pytest.mark.asyncio
292-
async def test_no_errors_without_request(app, sentry_init):
295+
async def test_no_errors_without_request(sentry_init):
293296
sentry_init(integrations=[quart_sentry.QuartIntegration()])
297+
app = quart_app_factory()
298+
294299
async with app.app_context():
295300
capture_exception(ValueError())
296301

297302

298-
def test_cli_commands_raise(app):
303+
def test_cli_commands_raise():
304+
app = quart_app_factory()
305+
299306
if not hasattr(app, "cli"):
300307
pytest.skip("Too old quart version")
301308

@@ -312,8 +319,9 @@ def foo():
312319

313320

314321
@pytest.mark.asyncio
315-
async def test_500(sentry_init, app):
322+
async def test_500(sentry_init):
316323
sentry_init(integrations=[quart_sentry.QuartIntegration()])
324+
app = quart_app_factory()
317325

318326
@app.route("/")
319327
async def index():
@@ -330,8 +338,9 @@ async def error_handler(err):
330338

331339

332340
@pytest.mark.asyncio
333-
async def test_error_in_errorhandler(sentry_init, capture_events, app):
341+
async def test_error_in_errorhandler(sentry_init, capture_events):
334342
sentry_init(integrations=[quart_sentry.QuartIntegration()])
343+
app = quart_app_factory()
335344

336345
@app.route("/")
337346
async def index():
@@ -358,8 +367,9 @@ async def error_handler(err):
358367

359368

360369
@pytest.mark.asyncio
361-
async def test_bad_request_not_captured(sentry_init, capture_events, app):
370+
async def test_bad_request_not_captured(sentry_init, capture_events):
362371
sentry_init(integrations=[quart_sentry.QuartIntegration()])
372+
app = quart_app_factory()
363373
events = capture_events()
364374

365375
@app.route("/")
@@ -374,8 +384,9 @@ async def index():
374384

375385

376386
@pytest.mark.asyncio
377-
async def test_does_not_leak_scope(sentry_init, capture_events, app):
387+
async def test_does_not_leak_scope(sentry_init, capture_events):
378388
sentry_init(integrations=[quart_sentry.QuartIntegration()])
389+
app = quart_app_factory()
379390
events = capture_events()
380391

381392
sentry_sdk.get_isolation_scope().set_tag("request_data", False)
@@ -402,8 +413,9 @@ async def generate():
402413

403414

404415
@pytest.mark.asyncio
405-
async def test_scoped_test_client(sentry_init, app):
416+
async def test_scoped_test_client(sentry_init):
406417
sentry_init(integrations=[quart_sentry.QuartIntegration()])
418+
app = quart_app_factory()
407419

408420
@app.route("/")
409421
async def index():
@@ -417,12 +429,13 @@ async def index():
417429
@pytest.mark.asyncio
418430
@pytest.mark.parametrize("exc_cls", [ZeroDivisionError, Exception])
419431
async def test_errorhandler_for_exception_swallows_exception(
420-
sentry_init, app, capture_events, exc_cls
432+
sentry_init, capture_events, exc_cls
421433
):
422434
# In contrast to error handlers for a status code, error
423435
# handlers for exceptions can swallow the exception (this is
424436
# just how the Quart signal works)
425437
sentry_init(integrations=[quart_sentry.QuartIntegration()])
438+
app = quart_app_factory()
426439
events = capture_events()
427440

428441
@app.route("/")
@@ -441,8 +454,9 @@ async def zerodivision(e):
441454

442455

443456
@pytest.mark.asyncio
444-
async def test_tracing_success(sentry_init, capture_events, app):
457+
async def test_tracing_success(sentry_init, capture_events):
445458
sentry_init(traces_sample_rate=1.0, integrations=[quart_sentry.QuartIntegration()])
459+
app = quart_app_factory()
446460

447461
@app.before_request
448462
async def _():
@@ -474,8 +488,9 @@ async def hi_tx():
474488

475489

476490
@pytest.mark.asyncio
477-
async def test_tracing_error(sentry_init, capture_events, app):
491+
async def test_tracing_error(sentry_init, capture_events):
478492
sentry_init(traces_sample_rate=1.0, integrations=[quart_sentry.QuartIntegration()])
493+
app = quart_app_factory()
479494

480495
events = capture_events()
481496

@@ -498,8 +513,9 @@ async def error():
498513

499514

500515
@pytest.mark.asyncio
501-
async def test_class_based_views(sentry_init, app, capture_events):
516+
async def test_class_based_views(sentry_init, capture_events):
502517
sentry_init(integrations=[quart_sentry.QuartIntegration()])
518+
app = quart_app_factory()
503519
events = capture_events()
504520

505521
@app.route("/")
@@ -523,12 +539,14 @@ async def dispatch_request(self):
523539

524540

525541
@pytest.mark.parametrize("endpoint", ["/sync/thread_ids", "/async/thread_ids"])
542+
@mock.patch("sentry_sdk.profiler.transaction_profiler.PROFILE_MINIMUM_SAMPLES", 0)
526543
@pytest.mark.asyncio
527-
async def test_active_thread_id(sentry_init, capture_envelopes, endpoint, app):
544+
async def test_active_thread_id(sentry_init, capture_envelopes, endpoint):
528545
sentry_init(
529546
traces_sample_rate=1.0,
530547
profiles_sample_rate=1.0,
531548
)
549+
app = quart_app_factory()
532550

533551
envelopes = capture_envelopes()
534552

@@ -559,12 +577,12 @@ async def test_active_thread_id(sentry_init, capture_envelopes, endpoint, app):
559577

560578

561579
@pytest.mark.asyncio
562-
async def test_span_origin(sentry_init, capture_events, app):
580+
async def test_span_origin(sentry_init, capture_events):
563581
sentry_init(
564582
integrations=[quart_sentry.QuartIntegration()],
565583
traces_sample_rate=1.0,
566584
)
567-
585+
app = quart_app_factory()
568586
events = capture_events()
569587

570588
client = app.test_client()

0 commit comments

Comments
 (0)