summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/assertions.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/testing/assertions.py')
-rw-r--r--lib/sqlalchemy/testing/assertions.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index 884556345..dfea33dc7 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -130,9 +130,16 @@ def _expect_warnings(exc_cls, messages, regex=True, assert_=True,
real_warn = warnings.warn
- def our_warn(msg, exception, *arg, **kw):
- if not issubclass(exception, exc_cls):
- return real_warn(msg, exception, *arg, **kw)
+ def our_warn(msg, *arg, **kw):
+ if isinstance(msg, exc_cls):
+ exception = msg
+ msg = str(exception)
+ elif arg:
+ exception = arg[0]
+ else:
+ exception = None
+ if not exception or not issubclass(exception, exc_cls):
+ return real_warn(msg, *arg, **kw)
if not filters:
return
@@ -143,7 +150,7 @@ def _expect_warnings(exc_cls, messages, regex=True, assert_=True,
seen.discard(filter_)
break
else:
- real_warn(msg, exception, *arg, **kw)
+ real_warn(msg, *arg, **kw)
with mock.patch("warnings.warn", our_warn):
yield