[sqlalchemy2] Turn on RemovedIn20Warnings in tests
Mark all sqlachemy deprecation warnings as 'error', but ignore each known deprecation at the moment. Each followup commit will remove one or more 'ignored' deprecation warnings and will also fix them. Change-Id: Iedcfc826962ad28446e91d44eea3071c11d16973
This commit is contained in:
parent
db03617acb
commit
f21fee9a72
87
octavia/tests/fixtures.py
Normal file
87
octavia/tests/fixtures.py
Normal file
@ -0,0 +1,87 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import warnings
|
||||
|
||||
import fixtures
|
||||
from sqlalchemy import exc as sqla_exc
|
||||
|
||||
|
||||
class WarningsFixture(fixtures.Fixture):
|
||||
"""Filters out warnings during test runs."""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
# Make deprecation warnings only happen once to avoid spamming
|
||||
warnings.simplefilter('once', DeprecationWarning)
|
||||
|
||||
# Enable deprecation warnings to capture upcoming SQLAlchemy changes
|
||||
warnings.filterwarnings(
|
||||
'error',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message='The Session.begin.subtransactions flag is deprecated ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message='The Session.autocommit parameter is deprecated ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message=r'The Query.get\(\) method is considered legacy ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message='The current statement is being autocommitted ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message='.* object is being merged into a Session along the ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message='Using strings to indicate column or relationship paths ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message='Using plain strings to indicate SQL statements without ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message='Using non-integer/slice indices on Row is deprecated ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message='Implicit coercion of SELECT and textual SELECT ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message=r'The "whens" argument to case\(\), ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
warnings.filterwarnings(
|
||||
'ignore',
|
||||
message='The create_engine.convert_unicode parameter and ',
|
||||
category=sqla_exc.SADeprecationWarning)
|
||||
|
||||
self.addCleanup(warnings.resetwarnings)
|
@ -25,11 +25,16 @@ from octavia.db import api as db_api
|
||||
from octavia.db import base_models
|
||||
from octavia.db import models
|
||||
|
||||
from octavia.tests import fixtures as oc_fixtures
|
||||
|
||||
|
||||
class OctaviaDBTestBase(test_base.BaseTestCase):
|
||||
|
||||
def setUp(self, connection_string='sqlite://'):
|
||||
super().setUp()
|
||||
|
||||
self.warning_fixture = self.useFixture(oc_fixtures.WarningsFixture())
|
||||
|
||||
# NOTE(blogan): doing this for now because using the engine and
|
||||
# session set up in the fixture for test_base.DbTestCase does not work
|
||||
# with the API functional tests. Need to investigate more if this
|
||||
|
@ -25,6 +25,8 @@ from octavia.common import rpc
|
||||
# needed for tests to function when run independently:
|
||||
from octavia.common import config # noqa: F401
|
||||
|
||||
from octavia.tests import fixtures as oc_fixtures
|
||||
|
||||
|
||||
class TestCase(testtools.TestCase):
|
||||
|
||||
@ -34,6 +36,8 @@ class TestCase(testtools.TestCase):
|
||||
self.addCleanup(mock.patch.stopall)
|
||||
self.addCleanup(self.clean_caches)
|
||||
|
||||
self.warning_fixture = self.useFixture(oc_fixtures.WarningsFixture())
|
||||
|
||||
def clean_caches(self):
|
||||
clients.NovaAuth.nova_client = None
|
||||
clients.NeutronAuth.neutron_client = None
|
||||
@ -44,6 +48,8 @@ class TestRpc(testtools.TestCase):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._buses = {}
|
||||
|
||||
self.warning_fixture = self.useFixture(oc_fixtures.WarningsFixture())
|
||||
|
||||
def _fake_create_transport(self, url):
|
||||
if url not in self._buses:
|
||||
self._buses[url] = messaging.get_rpc_transport(
|
||||
|
10
tox.ini
10
tox.ini
@ -6,7 +6,8 @@ ignore_basepython_conflict = True
|
||||
[testenv]
|
||||
usedevelop = True
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
PYTHONWARNINGS=default::DeprecationWarning
|
||||
PYTHONWARNINGS=always::DeprecationWarning
|
||||
SQLALCHEMY_WARN_20=1
|
||||
install_command =
|
||||
pip install {opts} {packages}
|
||||
allowlist_externals = find
|
||||
@ -45,9 +46,16 @@ commands =
|
||||
coverage xml -o cover/coverage.xml
|
||||
coverage report --fail-under=92 --skip-covered
|
||||
|
||||
[testenv:py3]
|
||||
setenv = OS_TEST_PATH={toxinidir}/octavia/tests/unit
|
||||
PYTHONWARNINGS=always::DeprecationWarning
|
||||
SQLALCHEMY_WARN_20=1
|
||||
|
||||
[testenv:functional]
|
||||
# This will use whatever 'basepython' is set to, so the name is ambiguous.
|
||||
setenv = OS_TEST_PATH={toxinidir}/octavia/tests/functional
|
||||
PYTHONWARNINGS=always::DeprecationWarning
|
||||
SQLALCHEMY_WARN_20=1
|
||||
|
||||
[testenv:functional-py3]
|
||||
setenv = OS_TEST_PATH={toxinidir}/octavia/tests/functional
|
||||
|
Loading…
x
Reference in New Issue
Block a user