Merge "tests: Enable SQLAlchemy 2.0 deprecation warnings"
This commit is contained in:
commit
1ca04117b9
@ -82,9 +82,11 @@ class HeatTestCase(testscenarios.WithScenarios,
|
|||||||
|
|
||||||
def setUp(self, mock_keystone=True, mock_resource_policy=True,
|
def setUp(self, mock_keystone=True, mock_resource_policy=True,
|
||||||
quieten_logging=True, mock_find_file=True):
|
quieten_logging=True, mock_find_file=True):
|
||||||
super(HeatTestCase, self).setUp()
|
super().setUp()
|
||||||
self.setup_logging(quieten=quieten_logging)
|
self.setup_logging(quieten=quieten_logging)
|
||||||
self.warnings = self.useFixture(fixtures.WarningsCapture())
|
|
||||||
|
self.useFixture(utils.WarningsFixture())
|
||||||
|
|
||||||
scheduler.ENABLE_SLEEP = False
|
scheduler.ENABLE_SLEEP = False
|
||||||
self.useFixture(fixtures.MonkeyPatch(
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
'heat.common.exception._FATAL_EXCEPTION_FORMAT_ERRORS',
|
'heat.common.exception._FATAL_EXCEPTION_FORMAT_ERRORS',
|
||||||
|
@ -14,12 +14,14 @@
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import uuid
|
import uuid
|
||||||
|
import warnings
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_db import options
|
from oslo_db import options
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
from sqlalchemy import exc as sqla_exc
|
||||||
|
|
||||||
from heat.common import context
|
from heat.common import context
|
||||||
from heat.db.sqlalchemy import api as db_api
|
from heat.db.sqlalchemy import api as db_api
|
||||||
@ -235,6 +237,112 @@ class ForeignKeyConstraintFixture(fixtures.Fixture):
|
|||||||
self.addCleanup(disable_fks)
|
self.addCleanup(disable_fks)
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# Enable deprecation warnings for heat itself to capture upcoming
|
||||||
|
# SQLAlchemy changes
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'error',
|
||||||
|
module='heat',
|
||||||
|
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='heat',
|
||||||
|
message=r'The Engine.execute\(\) method is considered legacy ',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
module='heat',
|
||||||
|
message='The current statement is being autocommitted using ',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
module='heat',
|
||||||
|
message='Using strings to indicate column or relationship paths ',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
module='heat',
|
||||||
|
message=r'The Query.get\(\) method is considered legacy ',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
module='heat',
|
||||||
|
message='The Session.transaction attribute is considered legacy ',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
module='heat',
|
||||||
|
message='The Session.begin.subtransactions flag is deprecated ',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
module='heat',
|
||||||
|
message='The autoload parameter is deprecated ',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
module='heat',
|
||||||
|
message='The ``bind`` argument for schema methods that invoke ',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
module='heat',
|
||||||
|
message=r'The legacy calling style of select\(\) is deprecated ',
|
||||||
|
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='heat',
|
||||||
|
category=sqla_exc.SAWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.addCleanup(self._reset_warning_filters)
|
||||||
|
|
||||||
|
def _reset_warning_filters(self):
|
||||||
|
warnings.filters[:] = self._original_warning_filters
|
||||||
|
|
||||||
|
|
||||||
class AnyInstance(object):
|
class AnyInstance(object):
|
||||||
"""Comparator for validating allowed instance type."""
|
"""Comparator for validating allowed instance type."""
|
||||||
|
|
||||||
|
8
tox.ini
8
tox.ini
@ -5,9 +5,11 @@ minversion = 3.18.0
|
|||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
basepython = python3
|
basepython = python3
|
||||||
setenv = VIRTUAL_ENV={envdir}
|
setenv =
|
||||||
PYTHONWARNINGS=default::DeprecationWarning
|
OS_TEST_PATH=heat/tests
|
||||||
OS_TEST_PATH=heat/tests
|
PYTHONDONTWRITEBYTECODE=1
|
||||||
|
# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0
|
||||||
|
SQLALCHEMY_WARN_20=1
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
||||||
-r{toxinidir}/requirements.txt
|
-r{toxinidir}/requirements.txt
|
||||||
|
Loading…
Reference in New Issue
Block a user