diff options
author | Stephen Finucane <stephenfin@redhat.com> | 2021-07-16 12:04:14 +0100 |
---|---|---|
committer | Stephen Finucane <stephenfin@redhat.com> | 2021-07-29 16:37:02 +0100 |
commit | 40bce5a2baf75dc87dd591e0f71a00f221a2ba92 (patch) | |
tree | 61ccb30a39379c8dda94a367b308ac70a7ade09a /oslo_db/tests | |
parent | a6007a98b1ea111c3d41c8c00578543fa47fcab0 (diff) | |
download | oslo-db-40bce5a2baf75dc87dd591e0f71a00f221a2ba92.tar.gz |
tests: Enable SADeprecationWarning warnings
Highlight use of deprecated SQLAlchemy APIs to ensure we keep on top of
things. This requires resolving the following SADeprecationWarning
warnings:
The from_engine() method on Inspector is deprecated and will be
removed in a future release. Please use the sqlalchemy.inspect()
function on an Engine or Connection in order to acquire an Inspector.
The Column.copy() method is deprecated and will be removed in a future
release.
The ColumnCollectionConstraint.copy() method is deprecated and will be
removed in a future release.
There are more warnings to be resolved related to SQLAlchemy 2.0, but
those require a special environment option (SQLALCHEMY_WARN_20) to
trigger and a lot of work to resolve. We'll address those in a series of
follow-ups.
Change-Id: I34b395e6d50f4e4151178c327d94308e6f5d5b6e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'oslo_db/tests')
-rw-r--r-- | oslo_db/tests/base.py | 4 | ||||
-rw-r--r-- | oslo_db/tests/fixtures.py | 36 | ||||
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_utils.py | 3 |
3 files changed, 41 insertions, 2 deletions
diff --git a/oslo_db/tests/base.py b/oslo_db/tests/base.py index 8d15666..a74ef82 100644 --- a/oslo_db/tests/base.py +++ b/oslo_db/tests/base.py @@ -12,6 +12,8 @@ from oslotest import base +from oslo_db.tests import fixtures + class BaseTestCase(base.BaseTestCase): """Test case base class for all oslo.db unit tests.""" @@ -19,3 +21,5 @@ class BaseTestCase(base.BaseTestCase): def setUp(self): """Run before each test method to initialize test environment.""" super().setUp() + + self.warning_fixture = self.useFixture(fixtures.WarningsFixture()) diff --git a/oslo_db/tests/fixtures.py b/oslo_db/tests/fixtures.py new file mode 100644 index 0000000..c08a34d --- /dev/null +++ b/oslo_db/tests/fixtures.py @@ -0,0 +1,36 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import warnings + +import fixtures +from sqlalchemy import exc as sqla_exc + + +class WarningsFixture(fixtures.Fixture): + """Filters out warnings during test runs.""" + + def setUp(self): + super().setUp() + # Make deprecation warnings only happen once to avoid spamming + warnings.simplefilter('once', DeprecationWarning) + + warnings.filterwarnings( + 'error', message='Evaluating non-mapped column expression', + category=sqla_exc.SAWarning) + + # Enable deprecation warnings to capture upcoming SQLAlchemy changes + warnings.filterwarnings( + 'error', + category=sqla_exc.SADeprecationWarning) + + self.addCleanup(warnings.resetwarnings) diff --git a/oslo_db/tests/sqlalchemy/test_utils.py b/oslo_db/tests/sqlalchemy/test_utils.py index b86faf0..47d587d 100644 --- a/oslo_db/tests/sqlalchemy/test_utils.py +++ b/oslo_db/tests/sqlalchemy/test_utils.py @@ -24,7 +24,6 @@ from sqlalchemy import CheckConstraint from sqlalchemy import MetaData, Table, Column from sqlalchemy import ForeignKey, ForeignKeyConstraint from sqlalchemy.dialects.postgresql import psycopg2 -from sqlalchemy.engine import reflection from sqlalchemy.engine import url as sa_url from sqlalchemy.exc import OperationalError from sqlalchemy.ext.declarative import declarative_base @@ -796,7 +795,7 @@ class TestMigrationUtils(db_test_base._DbTestCase): utils.change_deleted_column_type_to_id_type(self.engine, table_name) utils.change_deleted_column_type_to_boolean(self.engine, table_name) - insp = reflection.Inspector.from_engine(self.engine) + insp = sqlalchemy.inspect(self.engine) real_indexes = insp.get_indexes(table_name) self.assertEqual(3, len(real_indexes)) for index in real_indexes: |