summaryrefslogtreecommitdiff
path: root/oslo_db/tests/fixtures.py
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-07-16 12:04:14 +0100
committerStephen Finucane <stephenfin@redhat.com>2021-07-29 16:37:02 +0100
commit40bce5a2baf75dc87dd591e0f71a00f221a2ba92 (patch)
tree61ccb30a39379c8dda94a367b308ac70a7ade09a /oslo_db/tests/fixtures.py
parenta6007a98b1ea111c3d41c8c00578543fa47fcab0 (diff)
downloadoslo-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/fixtures.py')
-rw-r--r--oslo_db/tests/fixtures.py36
1 files changed, 36 insertions, 0 deletions
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)