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] should provide a guide for how to resolve the outstanding issues.

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

Change-Id: I9e8d3e3a82c51c3c008ef7380f2f619ed492205e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2022-04-08 11:03:28 +01:00
parent 9a8583b2ef
commit 238e7f8920
2 changed files with 93 additions and 14 deletions

View File

@ -124,7 +124,7 @@ class WarningsFixture(fixtures.Fixture):
"""Filters out warnings during test runs."""
def setUp(self):
super(WarningsFixture, self).setUp()
super().setUp()
self._original_warning_filters = warnings.filters[:]
@ -166,18 +166,93 @@ class WarningsFixture(fixtures.Fixture):
module='cinder',
)
warnings.filterwarnings(
'ignore',
message='Policy ".*":".*" was deprecated in ',
module='oslo_policy',
category=UserWarning,
)
# Enable deprecation warnings for cinder itself to capture upcoming
# SQLAlchemy changes
warnings.filterwarnings(
'ignore',
category=sqla_exc.SADeprecationWarning,
)
# TODO: Make this an error and filter out individual failures
warnings.filterwarnings(
'once',
'error',
module='cinder',
category=sqla_exc.SADeprecationWarning,
)
# ...but filter everything out until we get around to fixing them
# TODO: Fix all of these
warnings.filterwarnings(
'ignore',
module='cinder',
message=r'The "whens" argument to case\(\) is now passed using ',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'ignore',
module='cinder',
message=r'The "whens" argument to case\(\), when referring to ',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'ignore',
module='cinder',
message='Using strings to indicate column or relationship paths ',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'ignore',
module='cinder',
message='Using strings to indicate relationship names in Query',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'ignore',
module='cinder',
message='The current statement is being autocommitted using ',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'ignore',
module='cinder',
message=r'The SelectBase.as_scalar\(\) method is deprecated ',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'ignore',
module='cinder',
message=r'Passing a string to Connection.execute\(\) is ',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'ignore',
module='cinder',
message='The Session.begin.subtransactions flag is deprecated ',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'ignore',
module='cinder',
message=r'The legacy calling style of select\(\) is deprecated ',
category=sqla_exc.SADeprecationWarning,
)
self.addCleanup(self._reset_warning_filters)
def _reset_warning_filters(self):

26
tox.ini
View File

@ -10,17 +10,21 @@ ignore_basepython_conflict=true
[testenv]
basepython = python3
setenv = VIRTUAL_ENV={envdir}
PYTHONWARNINGS=default::DeprecationWarning
OS_STDOUT_CAPTURE=1
OS_STDERR_CAPTURE=1
OS_TEST_TIMEOUT=60
OS_TEST_PATH=./cinder/tests/unit
usedevelop = True
install_command=python -m pip install -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} {opts} {packages}
deps = -r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt
usedevelop = true
setenv =
VIRTUAL_ENV={envdir}
OS_STDOUT_CAPTURE=1
OS_STDERR_CAPTURE=1
OS_TEST_TIMEOUT=60
OS_TEST_PATH=./cinder/tests/unit
PYTHONDONTWRITEBYTECODE=1
# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0
SQLALCHEMY_WARN_20=1
install_command =
python -m pip install -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} {opts} {packages}
deps =
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt
# By default stestr will set concurrency
# to ncpu, to specify something else use