From 238e7f8920aa7d4bfa26a334740f7fc1b3a04ad0 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 8 Apr 2022 11:03:28 +0100 Subject: [PATCH] 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 --- cinder/tests/fixtures.py | 81 ++++++++++++++++++++++++++++++++++++++-- tox.ini | 26 +++++++------ 2 files changed, 93 insertions(+), 14 deletions(-) diff --git a/cinder/tests/fixtures.py b/cinder/tests/fixtures.py index c0a372d2ebc..212ad77843e 100644 --- a/cinder/tests/fixtures.py +++ b/cinder/tests/fixtures.py @@ -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): diff --git a/tox.ini b/tox.ini index 94cc36f2cb1..9fa315187f2 100644 --- a/tox.ini +++ b/tox.ini @@ -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