diff --git a/aodh/tests/base.py b/aodh/tests/base.py index 679b1920f..6858a689d 100644 --- a/aodh/tests/base.py +++ b/aodh/tests/base.py @@ -14,23 +14,108 @@ # under the License. """Test base classes. """ + import fixtures import functools import os.path import unittest +import warnings import oslo_messaging.conffixture from oslo_utils import timeutils from oslotest import base +from sqlalchemy import exc as sqla_exc import webtest import aodh from aodh import messaging +class WarningsFixture(fixtures.Fixture): + """Filters out warnings during test runs.""" + + def setUp(self): + super().setUp() + + self._original_warning_filters = warnings.filters[:] + + warnings.simplefilter('once', DeprecationWarning) + + # FIXME(stephenfin): Determine if we need to replace use of best_match + warnings.filterwarnings( + 'ignore', + module='webob', + message='The behavior of AcceptValidHeader.best_match is ', + category=DeprecationWarning, + ) + + # FIXME(stephenfin): Determine if we need to replace use of best_match + warnings.filterwarnings( + 'ignore', + module='webob', + message='The behavior of .best_match for the Accept classes is ', + category=DeprecationWarning, + ) + + # FIXME(stephenfin): Update tests to resolve these issues + warnings.filterwarnings( + 'ignore', + module='oslo_policy', + message='Policy ".*": ".*" failed scope check. ', + category=UserWarning, + ) + + # Enable deprecation warnings for aodh itself to capture upcoming + # SQLAlchemy changes + + warnings.filterwarnings( + 'ignore', + category=sqla_exc.SADeprecationWarning, + ) + + warnings.filterwarnings( + 'error', + module='aodh', + 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='aodh', + message=r'The Engine.execute\(\) method is considered legacy ', + category=sqla_exc.SADeprecationWarning, + ) + + warnings.filterwarnings( + 'ignore', + module='aodh', + message='The current statement is being autocommitted using ', + 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='aodh', + category=sqla_exc.SAWarning, + ) + + self.addCleanup(self._reset_warning_filters) + + def _reset_warning_filters(self): + warnings.filters[:] = self._original_warning_filters + + class BaseTestCase(base.BaseTestCase): def setup_messaging(self, conf, exchange=None): self.useFixture(oslo_messaging.conffixture.ConfFixture(conf)) + self.useFixture(WarningsFixture()) conf.set_override("notification_driver", ["messaging"]) if not exchange: exchange = 'aodh' diff --git a/tox.ini b/tox.ini index 945971539..92e75a0e1 100644 --- a/tox.ini +++ b/tox.ini @@ -16,6 +16,8 @@ setenv = AODH_TEST_DEPS=postgresql,mysql mysql: AODH_TEST_DEPS=mysql postgresql: AODH_TEST_DEPS=postgresql +# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0 + SQLALCHEMY_WARN_20=1 deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} .[{env:AODH_TEST_DEPS}]