tests: Enable SQLAlchemy 2.0 deprecation warnings

Well, sort of. We enable them but immediately filter out the ones we're
actually seeing, the rationale being that we can address these in a
piecemeal fashion without the risk of introducing new issues.

There's a lot more to be done here. However, the work done in oslo.db
[1], nova [2], cinder [2] etc. should provide a guide for how to resolve
the outstanding issues.

[1] https://review.opendev.org/q/topic:sqlalchemy-20+project:openstack/oslo.db
[2] https://review.opendev.org/q/topic:sqlalchemy-20+project:openstack/nova
[3] https://review.opendev.org/q/topic:sqlalchemy-20+project:openstack/cinder

Change-Id: I5b11e63451b0e76969421fa8fe39ac2b920f90ab
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2023-07-14 14:02:38 +01:00
parent 171580c4d3
commit 384e630e16
3 changed files with 73 additions and 5 deletions

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -26,6 +24,7 @@ from testtools import matchers
from testtools import testcase
from taskflow import exceptions
from taskflow.tests import fixtures as taskflow_fixtures
from taskflow.tests import utils
from taskflow.utils import misc
@ -92,6 +91,10 @@ class ItemsEqual(object):
class TestCase(base.BaseTestCase):
"""Test case base class for all taskflow unit tests."""
def setUp(self):
super().setUp()
self.useFixture(taskflow_fixtures.WarningsFixture())
def makeTmpDir(self):
t_dir = self.useFixture(fixtures.TempDir())
return t_dir.path

View File

@ -0,0 +1,65 @@
# 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()
self._original_warning_filters = warnings.filters[:]
warnings.simplefilter('once', DeprecationWarning)
# The UUIDFields emits a warning if the value is not a valid UUID.
# Let's escalate that to an exception in the test to prevent adding
# violations.
warnings.filterwarnings('error', message='.*invalid UUID.*')
# Enable deprecation warnings for taskflow itself to capture upcoming
# SQLAlchemy changes
warnings.filterwarnings(
'ignore',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'error',
module='taskflow',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'ignore',
message='The current statement is being autocommitted',
module='taskflow',
category=sqla_exc.SADeprecationWarning,
)
# Enable general SQLAlchemy warnings also to ensure we're not doing
# silly stuff. It's possible that we'll need to filter things out here
# with future SQLAlchemy versions, but that's a good thing
warnings.filterwarnings(
'error',
module='taskflow',
category=sqla_exc.SAWarning,
)
self.addCleanup(self._reset_warning_filters)
def _reset_warning_filters(self):
warnings.filters[:] = self._original_warning_filters

View File

@ -1,11 +1,11 @@
[tox]
minversion = 3.1.0
minversion = 3.18.0
envlist = cover,docs,pep8,py3,pylint,update-states
ignore_basepython_conflict = True
[testenv]
basepython = python3
setenv =
# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0
SQLALCHEMY_WARN_20=1
# We need to install a bit more than just `test' because those drivers have
# custom tests that we always run
deps =