diff --git a/src/flask/app.py b/src/flask/app.py index c14360e3..c5b4205a 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -5,6 +5,7 @@ import inspect import os import sys import typing as t +import warnings import weakref from datetime import timedelta from functools import update_wrapper @@ -12,7 +13,6 @@ from inspect import iscoroutinefunction from itertools import chain from types import TracebackType from urllib.parse import quote as _url_quote -import warnings import click from werkzeug.datastructures import Headers @@ -252,8 +252,6 @@ class Flask(App): session_interface: SessionInterface = SecureCookieSessionInterface() def __init_subclass__(cls, **kwargs: t.Any) -> None: - import warnings - # These method signatures were updated to take a ctx param. Detect # overridden methods in subclasses that still have the old signature. # Show a deprecation warning and wrap to call with correct args. @@ -1598,7 +1596,6 @@ class Flask(App): Kept for backwards compatibility — it always returns False. """ - import warnings warnings.warn( "Flask.should_ignore_error is deprecated and will be removed in a " "future release. It currently always returns False and should not be used.", diff --git a/tests/test_should_ignore_error.py b/tests/test_should_ignore_error.py index 8348aa39..29c343c1 100644 --- a/tests/test_should_ignore_error.py +++ b/tests/test_should_ignore_error.py @@ -1,12 +1,15 @@ import pytest + from flask import Flask + def test_should_ignore_error_deprecation_warning(): """Minimal test: check DeprecationWarning and return value.""" app = Flask(__name__) with pytest.warns(DeprecationWarning): assert app.should_ignore_error(None) is False + @pytest.mark.parametrize("error", [Exception(), ValueError(), RuntimeError()]) def test_should_ignore_error_multiple_exceptions(error): """Verify that should_ignore_error issues a DeprecationWarning for multiple exception types.""" @@ -14,6 +17,7 @@ def test_should_ignore_error_multiple_exceptions(error): with pytest.warns(DeprecationWarning): assert app.should_ignore_error(error) is False + def test_should_ignore_error_returns_false(): """Verify that should_ignore_error always returns False.""" app = Flask(__name__) @@ -21,9 +25,10 @@ def test_should_ignore_error_returns_false(): result = app.should_ignore_error(Exception()) assert result is False + def test_should_ignore_error_warning_repeated_calls(): """Verify repeated calls each trigger a DeprecationWarning.""" app = Flask(__name__) for _ in range(3): with pytest.warns(DeprecationWarning): - assert app.should_ignore_error(Exception()) is False \ No newline at end of file + assert app.should_ignore_error(Exception()) is False