summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/warnings.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-01-23 10:51:55 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-01-23 12:58:38 -0500
commitaba3ab247da4628e4e7baf993702e2efaccbc547 (patch)
tree5aede9a6a560c3184ca0b2a86b3ad3d5715370d6 /lib/sqlalchemy/testing/warnings.py
parent321f64f71e7ecc7404da9b95e2e0aa1d692ac181 (diff)
downloadsqlalchemy-aba3ab247da4628e4e7baf993702e2efaccbc547.tar.gz
after all that, use pytest warnings plugin
The warnings plugin lets us set the filters up in the config, and as our filter requirements are now simple we can just set this up. additionally pytest now recommends pyproject.toml, since we fully include this now, let's move it there. the pytest logging plugin seems to not be any problem either at the moment, so re-enable that. if it becomes apparent whatever the problem was (which was probably that it was just surprising, or something) we can disable it again and comment what the reason was. Change-Id: Ia9715533b01f72aa5fdcf6a27ce75b76f829fa43
Diffstat (limited to 'lib/sqlalchemy/testing/warnings.py')
-rw-r--r--lib/sqlalchemy/testing/warnings.py42
1 files changed, 7 insertions, 35 deletions
diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py
index 1c2039602..2d65e68ec 100644
--- a/lib/sqlalchemy/testing/warnings.py
+++ b/lib/sqlalchemy/testing/warnings.py
@@ -4,54 +4,26 @@
#
# This module is part of SQLAlchemy and is released under
# the MIT License: https://www.opensource.org/licenses/mit-license.php
-import warnings
-
from . import assertions
from .. import exc as sa_exc
+from ..exc import SATestSuiteWarning
from ..util.langhelpers import _warnings_warn
-class SATestSuiteWarning(Warning):
- """warning for a condition detected during tests that is non-fatal
-
- Currently outside of SAWarning so that we can work around tools like
- Alembic doing the wrong thing with warnings.
-
- """
-
-
def warn_test_suite(message):
_warnings_warn(message, category=SATestSuiteWarning)
def setup_filters():
- """Set global warning behavior for the test suite."""
-
- # TODO: at this point we can use the normal pytest warnings plugin,
- # if we decide the test suite can be linked to pytest only
-
- origin = r"^(?:test|sqlalchemy)\..*"
+ """hook for setting up warnings filters.
- warnings.filterwarnings(
- "ignore", category=sa_exc.SAPendingDeprecationWarning
- )
- warnings.filterwarnings("error", category=sa_exc.SADeprecationWarning)
- warnings.filterwarnings("error", category=sa_exc.SAWarning)
+ Note that when the pytest warnings plugin is in place, that plugin
+ overwrites whatever happens here.
- warnings.filterwarnings("always", category=SATestSuiteWarning)
+ Current SQLAlchemy 2.0 default is to use pytest warnings plugin
+ which is configured in pyproject.toml.
- warnings.filterwarnings(
- "error", category=DeprecationWarning, module=origin
- )
-
- try:
- import pytest
- except ImportError:
- pass
- else:
- warnings.filterwarnings(
- "once", category=pytest.PytestDeprecationWarning, module=origin
- )
+ """
def assert_warnings(fn, warning_msgs, regex=False):