]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Revert SQLAlchemy warnings to warnings.py
authorFederico Caselli <cfederico87@gmail.com>
Sun, 20 Feb 2022 11:03:19 +0000 (12:03 +0100)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 21 Feb 2022 15:20:22 +0000 (10:20 -0500)
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

lib/sqlalchemy/testing/warnings.py
pyproject.toml

index e82566be766dbbce8a7ae7607b203131c0d941c4..491b8b2cb82b9b3df624d5b75989b7e1c2cb5ef1 100644 (file)
@@ -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):
index f7750b6a6ba24f12aec03eb6b8988f110f986435..e79c7292df754b756518f80477b2c6fb939203fd 100644 (file)
@@ -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"
 ]