From: Federico Caselli Date: Sun, 20 Feb 2022 11:03:19 +0000 (+0100) Subject: Revert SQLAlchemy warnings to warnings.py X-Git-Tag: rel_2_0_0b1~476^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a02b0ef482075eb0b967c833c1bd3db677e561b2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Revert SQLAlchemy warnings to warnings.py Configuring the warning filters in pyproject breaks tests if no sqlalchemy is installed in the env, since the filters are processed before loading conftest. It also may interfere with coverage. Revises Ia9715533b01f72aa5fdcf6a27ce75b76f829fa43 aba3ab247da4628e4e7baf993702e2efaccbc547 Change-Id: I51448a6a014f31d3088dce54cd20d1e683500f8c --- diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py index e82566be76..491b8b2cb8 100644 --- a/lib/sqlalchemy/testing/warnings.py +++ b/lib/sqlalchemy/testing/warnings.py @@ -6,7 +6,10 @@ # the MIT License: https://www.opensource.org/licenses/mit-license.php from __future__ import annotations +import warnings + from . import assertions +from .. import exc from .. import exc as sa_exc from ..exc import SATestSuiteWarning from ..util.langhelpers import _warnings_warn @@ -19,13 +22,15 @@ def warn_test_suite(message): def setup_filters(): """hook for setting up warnings filters. - Note that when the pytest warnings plugin is in place, that plugin - overwrites whatever happens here. - - Current SQLAlchemy 2.0 default is to use pytest warnings plugin - which is configured in pyproject.toml. + SQLAlchemy-specific classes must only be here and not in pytest config, + as we need to delay importing SQLAlchemy until conftest.py has been + processed. """ + warnings.filterwarnings("ignore", category=exc.SAPendingDeprecationWarning) + warnings.filterwarnings("error", category=exc.SADeprecationWarning) + warnings.filterwarnings("error", category=exc.SAWarning) + warnings.filterwarnings("always", category=exc.SATestSuiteWarning) def assert_warnings(fn, warning_msgs, regex=False): diff --git a/pyproject.toml b/pyproject.toml index f7750b6a6b..e79c7292df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,10 +23,10 @@ addopts = "--tb native -v -r sfxX --maxfail=250 -p warnings -p logging --strict- python_files = "test/*test_*.py" minversion = "6.2" filterwarnings = [ - "ignore::sqlalchemy.exc.SAPendingDeprecationWarning", - "error::sqlalchemy.exc.SADeprecationWarning", - "error::sqlalchemy.exc.SAWarning", - "always::sqlalchemy.exc.SATestSuiteWarning", + # NOTE: additional SQLAlchemy specific filters in + # sqlalchemy/testing/warnings.py. SQLAlchemy modules cannot be named + # here as pytest loads them immediately, which breaks coverage as well + # as sys.path adjustments in conftest.py "error::DeprecationWarning:test", "error::DeprecationWarning:sqlalchemy" ]