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.""" """Filters out warnings during test runs."""
def setUp(self): def setUp(self):
super(WarningsFixture, self).setUp() super().setUp()
self._original_warning_filters = warnings.filters[:] self._original_warning_filters = warnings.filters[:]
@ -166,18 +166,93 @@ class WarningsFixture(fixtures.Fixture):
module='cinder', 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( warnings.filterwarnings(
'ignore', 'ignore',
category=sqla_exc.SADeprecationWarning, category=sqla_exc.SADeprecationWarning,
) )
# TODO: Make this an error and filter out individual failures
warnings.filterwarnings( warnings.filterwarnings(
'once', 'error',
module='cinder', module='cinder',
category=sqla_exc.SADeprecationWarning, 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) self.addCleanup(self._reset_warning_filters)
def _reset_warning_filters(self): def _reset_warning_filters(self):

26
tox.ini
View File

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