summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/assertions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-04-30 18:27:24 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2023-05-09 20:23:48 -0400
commit60b31198311eedfa3814e7098c94d3aa29338fdd (patch)
tree5fe3a55ef67ab14fa63a0a3122a1326b830ceb72 /lib/sqlalchemy/testing/assertions.py
parent228490ead7048f2e558c25b0f055bdb952272ec4 (diff)
downloadsqlalchemy-60b31198311eedfa3814e7098c94d3aa29338fdd.tar.gz
fix test suite warnings
fix a handful of warnings that were emitting but not raising, usually because they were inside an "expect_warnings" block. modify "expect_warnings" to always use "raise_on_any_unexpected" behavior; remove this parameter. Fixed issue in semi-private ``await_only()`` and ``await_fallback()`` concurrency functions where the given awaitable would remain un-awaited if the function threw a ``GreenletError``, which could cause "was not awaited" warnings later on if the program continued. In this case, the given awaitable is now cancelled before the exception is thrown. Change-Id: I33668c5e8c670454a3d879e559096fb873b57244
Diffstat (limited to 'lib/sqlalchemy/testing/assertions.py')
-rw-r--r--lib/sqlalchemy/testing/assertions.py42
1 files changed, 32 insertions, 10 deletions
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index a51d831a9..e7b416167 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -47,7 +47,7 @@ def expect_warnings(*messages, **kw):
Note that the test suite sets SAWarning warnings to raise exceptions.
""" # noqa
- return _expect_warnings(sa_exc.SAWarning, messages, **kw)
+ return _expect_warnings_sqla_only(sa_exc.SAWarning, messages, **kw)
@contextlib.contextmanager
@@ -84,11 +84,15 @@ def emits_warning(*messages):
def expect_deprecated(*messages, **kw):
- return _expect_warnings(sa_exc.SADeprecationWarning, messages, **kw)
+ return _expect_warnings_sqla_only(
+ sa_exc.SADeprecationWarning, messages, **kw
+ )
def expect_deprecated_20(*messages, **kw):
- return _expect_warnings(sa_exc.Base20DeprecationWarning, messages, **kw)
+ return _expect_warnings_sqla_only(
+ sa_exc.Base20DeprecationWarning, messages, **kw
+ )
def emits_warning_on(db, *messages):
@@ -140,6 +144,29 @@ _SEEN = None
_EXC_CLS = None
+def _expect_warnings_sqla_only(
+ exc_cls,
+ messages,
+ regex=True,
+ search_msg=False,
+ assert_=True,
+):
+ """SQLAlchemy internal use only _expect_warnings().
+
+ Alembic is using _expect_warnings() directly, and should be updated
+ to use this new interface.
+
+ """
+ return _expect_warnings(
+ exc_cls,
+ messages,
+ regex=regex,
+ search_msg=search_msg,
+ assert_=assert_,
+ raise_on_any_unexpected=True,
+ )
+
+
@contextlib.contextmanager
def _expect_warnings(
exc_cls,
@@ -150,7 +177,6 @@ def _expect_warnings(
raise_on_any_unexpected=False,
squelch_other_warnings=False,
):
-
global _FILTERS, _SEEN, _EXC_CLS
if regex or search_msg:
@@ -181,7 +207,6 @@ def _expect_warnings(
real_warn = warnings.warn
def our_warn(msg, *arg, **kw):
-
if isinstance(msg, _EXC_CLS):
exception = type(msg)
msg = str(msg)
@@ -379,7 +404,7 @@ def assert_warns(except_cls, callable_, *args, **kwargs):
"""
- with _expect_warnings(except_cls, [".*"], squelch_other_warnings=True):
+ with _expect_warnings_sqla_only(except_cls, [".*"]):
return callable_(*args, **kwargs)
@@ -394,12 +419,11 @@ def assert_warns_message(except_cls, msg, callable_, *args, **kwargs):
rather than regex.match().
"""
- with _expect_warnings(
+ with _expect_warnings_sqla_only(
except_cls,
[msg],
search_msg=True,
regex=False,
- squelch_other_warnings=True,
):
return callable_(*args, **kwargs)
@@ -413,7 +437,6 @@ def assert_raises_message_context_ok(
def _assert_raises(
except_cls, callable_, args, kwargs, msg=None, check_context=False
):
-
with _expect_raises(except_cls, msg, check_context) as ec:
callable_(*args, **kwargs)
return ec.error
@@ -892,7 +915,6 @@ class AssertsExecutionResults:
return result
def assert_sql(self, db, callable_, rules):
-
newrules = []
for rule in rules:
if isinstance(rule, dict):