summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/assertions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-05-22 14:08:55 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-05-22 15:51:07 -0400
commit9f0fb6c601829cb7c9f449d57e12e8b95dab51f5 (patch)
tree1201e89aa89fac39316ccfa87567a88b9667fa4c /lib/sqlalchemy/testing/assertions.py
parentda1bc9878b71f6f7b87e2fa7895e1631ae581609 (diff)
downloadsqlalchemy-9f0fb6c601829cb7c9f449d57e12e8b95dab51f5.tar.gz
Allow metadata.reflect() to recover from unreflectable tables
Added support for views that are unreflectable due to stale table definitions, when calling :meth:`.MetaData.reflect`; a warning is emitted for the table that cannot respond to ``DESCRIBE`` but the operation succeeds. The MySQL dialect now raises UnreflectableTableError which is in turn caught by MetaData.reflect(). Reflecting the view standalone raises this error directly. Change-Id: Id8005219d8e073c154cc84a873df911b4a6cf4d6 Fixes: #3871
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