summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqlalchemy/exc.py9
-rw-r--r--lib/sqlalchemy/pool/base.py13
-rw-r--r--lib/sqlalchemy/testing/warnings.py42
-rw-r--r--pyproject.toml14
-rw-r--r--setup.cfg5
-rw-r--r--test/base/test_except.py1
-rwxr-xr-xtest/conftest.py2
7 files changed, 46 insertions, 40 deletions
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py
index f5b9f6e75..8fdacbdf2 100644
--- a/lib/sqlalchemy/exc.py
+++ b/lib/sqlalchemy/exc.py
@@ -672,6 +672,15 @@ class NotSupportedError(DatabaseError):
# Warnings
+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.
+
+ """
+
+
class SADeprecationWarning(HasDescriptionCode, DeprecationWarning):
"""Issued for usage of deprecated APIs."""
diff --git a/lib/sqlalchemy/pool/base.py b/lib/sqlalchemy/pool/base.py
index 0512582f8..6c770e201 100644
--- a/lib/sqlalchemy/pool/base.py
+++ b/lib/sqlalchemy/pool/base.py
@@ -757,13 +757,14 @@ def _finalize_fairy(
else:
message = (
"The garbage collector is trying to clean up "
- "connection %r. This feature is unsupported on async "
+ f"connection {dbapi_connection!r}. This feature is "
+ "unsupported on async "
"dbapi, since no IO can be performed at this stage to "
"reset the connection. Please close out all "
"connections when they are no longer used, calling "
"``close()`` or using a context manager to "
"manage their lifetime."
- ) % dbapi_connection
+ )
pool.logger.error(message)
util.warn(message)
@@ -779,6 +780,14 @@ def _finalize_fairy(
if connection_record and connection_record.fairy_ref is not None:
connection_record.checkin()
+ # give gc some help. See
+ # test/engine/test_pool.py::PoolEventsTest::test_checkin_event_gc[True]
+ # which actually started failing when pytest warnings plugin was
+ # turned on, due to util.warn() above
+ del dbapi_connection
+ del connection_record
+ del fairy
+
# a dictionary of the _ConnectionFairy weakrefs to _ConnectionRecord, so that
# GC under pypy will call ConnectionFairy finalizers. linked directly to the
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):
diff --git a/pyproject.toml b/pyproject.toml
index 9b0b3dfc7..2707bea97 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -9,3 +9,17 @@
[tool.black]
line-length = 79
target-version = ['py37']
+
+
+[tool.pytest.ini_options]
+addopts = "--tb native -v -r sfxX --maxfail=250 -p warnings -p logging"
+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",
+ "error::DeprecationWarning:test",
+ "error::DeprecationWarning:sqlalchemy"
+]
diff --git a/setup.cfg b/setup.cfg
index e841348ce..3f903eb62 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -85,9 +85,8 @@ tag_build = dev
[options.packages.find]
where = lib
-[tool:pytest]
-addopts = --tb native -v -r sfxX --maxfail=250 -p no:warnings -p no:logging
-python_files = test/*test_*.py
+# [tool:pytest]
+# pytest settings moved to pyproject.toml
[upload]
sign = 1
diff --git a/test/base/test_except.py b/test/base/test_except.py
index c7ef304b3..77f5c731a 100644
--- a/test/base/test_except.py
+++ b/test/base/test_except.py
@@ -511,6 +511,7 @@ ALL_EXC = [
[lambda cls: cls("foo", code="42")],
),
([sa_exceptions.SAPendingDeprecationWarning], [lambda cls: cls(1, 2, 3)]),
+ ([sa_exceptions.SATestSuiteWarning], [lambda cls: cls()]),
]
diff --git a/test/conftest.py b/test/conftest.py
index 921a4aadc..d082f44a1 100755
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -16,6 +16,8 @@ os.environ["SQLALCHEMY_WARN_20"] = "true"
collect_ignore_glob = []
+# this requires that sqlalchemy.testing was not already
+# imported in order to work
pytest.register_assert_rewrite("sqlalchemy.testing.assertions")