Merge "tests: Enable SQLAlchemy 2.0 deprecation warnings"

This commit is contained in:
Zuul 2023-08-28 18:12:50 +00:00 committed by Gerrit Code Review
commit b6223f3210
2 changed files with 159 additions and 2 deletions

View File

@ -21,7 +21,9 @@ import warnings
import fixtures as pyfixtures import fixtures as pyfixtures
from openstack.identity.v3 import endpoint from openstack.identity.v3 import endpoint
from openstack.identity.v3 import limit as klimit from openstack.identity.v3 import limit as klimit
from oslo_db import warning as oslo_db_warning
from oslo_limit import limit from oslo_limit import limit
from sqlalchemy import exc as sqla_exc
_TRUE_VALUES = ('True', 'true', '1', 'yes') _TRUE_VALUES = ('True', 'true', '1', 'yes')
@ -141,6 +143,159 @@ class WarningsFixture(pyfixtures.Fixture):
warnings.filterwarnings( warnings.filterwarnings(
'error', message="Property '.*' has moved to '.*'") 'error', message="Property '.*' has moved to '.*'")
# Don't warn for our own deprecation warnings
warnings.filterwarnings(
'ignore',
module='glance',
category=DeprecationWarning,
)
# Disable deprecation warning for oslo.db's EngineFacade. We *really*
# need to get off this but it's not happening while sqlalchemy 2.0
# stuff is ongoing
warnings.filterwarnings(
'ignore',
category=oslo_db_warning.OsloDBDeprecationWarning,
message='EngineFacade is deprecated',
)
# Enable deprecation warnings for glance itself to capture upcoming
# SQLAlchemy changes
warnings.filterwarnings(
'ignore',
category=sqla_exc.SADeprecationWarning,
)
warnings.filterwarnings(
'error',
module='glance',
category=sqla_exc.SADeprecationWarning,
)
# ...but filter everything out until we get around to fixing them
# TODO(stephenfin): Fix all of these
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message=r'Invoking and_\(\) without arguments is deprecated',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message='The current statement is being autocommitted ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message='The ``aliased`` and ``from_joinpoint`` keyword ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message=r'The "whens" argument to case\(\), ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message='Using non-integer/slice indices on Row is deprecated ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message='The MetaData.bind argument is deprecated ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message=r'Passing a string to Connection.execute\(\) ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message=r'The Engine.execute\(\) method is considered legacy ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message=r'The autoload parameter is deprecated ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message=r'Query.values\(\) is deprecated ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message='The insert.values parameter will be removed ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message=r'The ``bind`` argument for schema methods ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message=r'The legacy calling style of select\(\) ',
)
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SADeprecationWarning,
message=r'The Executable.execute\(\) method is considered legacy ',
)
# 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='glance',
category=sqla_exc.SAWarning,
)
# ...but filter everything out until we get around to fixing them
# TODO(stephenfin): Fix all of these
warnings.filterwarnings(
'ignore',
module='glance',
category=sqla_exc.SAWarning,
message='Class DeleteFromSelect will not make use of SQL ',
)
self.addCleanup(self._reset_warning_filters) self.addCleanup(self._reset_warning_filters)
def _reset_warning_filters(self): def _reset_warning_filters(self):

View File

@ -6,8 +6,6 @@ skip_missing_interpreters = true
[testenv] [testenv]
setenv = setenv =
VIRTUAL_ENV={envdir}
PYTHONWARNINGS=default::DeprecationWarning
# NOTE(hemanthm): The environment variable "OS_TEST_DBAPI_ADMIN_CONNECTION" # NOTE(hemanthm): The environment variable "OS_TEST_DBAPI_ADMIN_CONNECTION"
# must be set to force oslo.db tests to use a file-based sqlite database # must be set to force oslo.db tests to use a file-based sqlite database
# instead of the default in-memory database, which doesn't work well with # instead of the default in-memory database, which doesn't work well with
@ -17,6 +15,8 @@ setenv =
# part of its test clean-up. Think of setting this environment variable as a # part of its test clean-up. Think of setting this environment variable as a
# clue for oslo.db to use file-based database. # clue for oslo.db to use file-based database.
OS_TEST_DBAPI_ADMIN_CONNECTION=sqlite:////tmp/placeholder-never-created-nor-used.db OS_TEST_DBAPI_ADMIN_CONNECTION=sqlite:////tmp/placeholder-never-created-nor-used.db
# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0
SQLALCHEMY_WARN_20=1
usedevelop = True usedevelop = True
install_command = python -m pip install -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} {opts} {packages} 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 deps = -r{toxinidir}/test-requirements.txt
@ -34,6 +34,8 @@ passenv =
[testenv:functional] [testenv:functional]
setenv = setenv =
TEST_PATH = ./glance/tests/functional TEST_PATH = ./glance/tests/functional
# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0
SQLALCHEMY_WARN_20=1
commands = stestr run {posargs} commands = stestr run {posargs}
[testenv:functional-py{38,39,310,311}] [testenv:functional-py{38,39,310,311}]