diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-22 22:56:36 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-03-23 13:45:52 -0400 |
| commit | 9ec860e7a5c944799f9ef4de9069d707cfc1ed27 (patch) | |
| tree | d02f035c3f2210e4760d39b73db738f993960e16 /lib/sqlalchemy/testing | |
| parent | 2b7518ad7b4c4bb4ae6bd07221d349ac1a6af9a5 (diff) | |
| download | sqlalchemy-9ec860e7a5c944799f9ef4de9069d707cfc1ed27.tar.gz | |
Remove internal use of string attr in loader option
Fixed issue where a "removed in 2.0" warning were generated internally by
the relationship loader mechanics.
This changeset started the effort of converting all string usage
in the test suite, however this is a much longer job as the
use of strings in loader options is widespread. In particular
I'm not totally comfortable with strings not being accepted
in obvious spots like Load(User).load_only("x", "y", "z"), which
points to a new string expecting functionality that's not
what's there now. However at the moment it seems like we need
to continue removing all support for strings and then figure out
"immediate strings from an explicit class" later.
Fixes: #6115
Change-Id: I6b314d135d2bc049fd66500914b772c1fe60b5b3
Diffstat (limited to 'lib/sqlalchemy/testing')
| -rw-r--r-- | lib/sqlalchemy/testing/assertions.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py index 289ac9a0a..02137474b 100644 --- a/lib/sqlalchemy/testing/assertions.py +++ b/lib/sqlalchemy/testing/assertions.py @@ -135,7 +135,12 @@ def uses_deprecated(*messages): @contextlib.contextmanager def _expect_warnings( - exc_cls, messages, regex=True, assert_=True, py2konly=False + exc_cls, + messages, + regex=True, + assert_=True, + py2konly=False, + raise_on_any_unexpected=False, ): if regex: @@ -145,7 +150,13 @@ def _expect_warnings( seen = set(filters) - real_warn = warnings.warn + if raise_on_any_unexpected: + + def real_warn(msg, *arg, **kw): + raise AssertionError("Got unexpected warning: %r" % msg) + + else: + real_warn = warnings.warn def our_warn(msg, *arg, **kw): if isinstance(msg, exc_cls): @@ -159,7 +170,7 @@ def _expect_warnings( if not exception or not issubclass(exception, exc_cls): return real_warn(msg, *arg, **kw) - if not filters: + if not filters and not raise_on_any_unexpected: return for filter_ in filters: |
