From 059eaaa7b322c088de38cb4c32e91c8842845256 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 15 Jun 2023 15:08:47 -0700 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 bit more to be done here. However, the work done in oslo.db and other projects [1] should provide a guide for how to resolve the outstanding issues. [1] https://review.opendev.org/q/topic:sqlalchemy-20 Change-Id: I36a79377016a6913f2c63cac4c820ad8342ffbf6 Signed-off-by: Stephen Finucane --- barbican/tests/fixture.py | 39 +++++++++++++++++++++++++++++++++++++++ tox.ini | 2 ++ 2 files changed, 41 insertions(+) diff --git a/barbican/tests/fixture.py b/barbican/tests/fixture.py index 6de5331bb..a1336c87a 100644 --- a/barbican/tests/fixture.py +++ b/barbican/tests/fixture.py @@ -18,6 +18,7 @@ import fixtures from oslo_db.sqlalchemy import session from oslo_utils import timeutils import sqlalchemy as sa +from sqlalchemy import exc as sqla_exc from barbican.model import models @@ -175,6 +176,44 @@ class WarningsFixture(fixtures.Fixture): warnings.simplefilter('once', DeprecationWarning) + # Enable deprecation warnings for barbican itself to capture upcoming + # SQLAlchemy changes + + warnings.filterwarnings( + 'ignore', + category=sqla_exc.SADeprecationWarning, + ) + + warnings.filterwarnings( + 'error', + module='barbican', + category=sqla_exc.SADeprecationWarning, + ) + + warnings.filterwarnings( + 'ignore', + module='barbican', + message=r'".*" object is being merged into a Session along .*', + category=sqla_exc.SADeprecationWarning, + ) + + warnings.filterwarnings( + 'ignore', + module='barbican', + message=r'The legacy calling style of select\(\) .*', + 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='barbican', + category=sqla_exc.SAWarning, + ) + self.addCleanup(self._reset_warning_filters) def _reset_warning_filters(self): diff --git a/tox.ini b/tox.ini index f60012a40..c43a7e8c0 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,8 @@ envlist = py38,py39,pep8,docs setenv = PYTHON=coverage run --source barbican --parallel-mode PYTHONDONTWRITEBYTECODE=1 +# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0 + SQLALCHEMY_WARN_20=1 usedevelop = True deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}