diff --git a/tests/integrations/flask/test_flask.py b/tests/integrations/flask/test_flask.py index 09b2c2fb30..3d3572e2d3 100644 --- a/tests/integrations/flask/test_flask.py +++ b/tests/integrations/flask/test_flask.py @@ -1,10 +1,9 @@ import json import re -import pytest import logging - from io import BytesIO +import pytest from flask import ( Flask, Response, @@ -14,9 +13,14 @@ render_template_string, ) from flask.views import View - from flask_login import LoginManager, login_user +try: + from werkzeug.wrappers.request import UnsupportedMediaType +except ImportError: + UnsupportedMediaType = None + +import sentry_sdk.integrations.flask as flask_sentry from sentry_sdk import ( set_tag, configure_scope, @@ -26,7 +30,6 @@ Hub, ) from sentry_sdk.integrations.logging import LoggingIntegration -import sentry_sdk.integrations.flask as flask_sentry from sentry_sdk.serializer import MAX_DATABAG_BREADTH @@ -340,7 +343,11 @@ def test_flask_medium_formdata_request(sentry_init, capture_events, app): def index(): assert request.form["foo"] == data["foo"] assert not request.get_data() - assert not request.get_json() + try: + assert not request.get_json() + except UnsupportedMediaType: + # flask/werkzeug 3 + pass capture_message("hi") return "ok" @@ -372,7 +379,11 @@ def index(): assert request.form["username"] == data["username"] assert request.form["age"] == data["age"] assert not request.get_data() - assert not request.get_json() + try: + assert not request.get_json() + except UnsupportedMediaType: + # flask/werkzeug 3 + pass set_tag("view", "yes") capture_message("hi") return "ok" @@ -405,7 +416,11 @@ def index(): assert request.get_data() == data else: assert request.get_data() == data.encode("ascii") - assert not request.get_json() + try: + assert not request.get_json() + except UnsupportedMediaType: + # flask/werkzeug 3 + pass capture_message("hi") return "ok" @@ -431,7 +446,11 @@ def test_flask_files_and_form(sentry_init, capture_events, app): def index(): assert list(request.form) == ["foo"] assert list(request.files) == ["file"] - assert not request.get_json() + try: + assert not request.get_json() + except UnsupportedMediaType: + # flask/werkzeug 3 + pass capture_message("hi") return "ok" @@ -545,9 +564,12 @@ def test_cli_commands_raise(app): def foo(): 1 / 0 + def create_app(*_): + return app + with pytest.raises(ZeroDivisionError): app.cli.main( - args=["foo"], prog_name="myapp", obj=ScriptInfo(create_app=lambda _: app) + args=["foo"], prog_name="myapp", obj=ScriptInfo(create_app=create_app) ) diff --git a/tox.ini b/tox.ini index 072b561b07..c38d60332c 100644 --- a/tox.ini +++ b/tox.ini @@ -95,6 +95,7 @@ envlist = {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9}-flask-v{0.11,0.12,1.0} {py2.7,py3.5,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-flask-v{1.1} {py3.6,py3.8,py3.9,py3.10,py3.11,py3.12}-flask-v{2.0} + {py3.10,py3.11,py3.12}-flask-v{3.0} # Gevent {py2.7,py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-gevent @@ -333,12 +334,14 @@ deps = # Flask flask: flask-login - flask: Werkzeug<2.1.0 + flask-v{0.11,0.12,1.0,1.1,2.0}: Werkzeug<2.1.0 + flask-v{3.0}: Werkzeug flask-v0.11: Flask>=0.11,<0.12 flask-v0.12: Flask>=0.12,<0.13 flask-v1.0: Flask>=1.0,<1.1 flask-v1.1: Flask>=1.1,<1.2 flask-v2.0: Flask>=2.0,<2.1 + flask-v3.0: Flask>=3.0,<3.1 # Gevent # See http://www.gevent.org/install.html#older-versions-of-python