# 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
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):
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"
]