Merge "Add fixture to only emit DeprecationWarning once"

This commit is contained in:
Zuul 2017-11-22 02:46:07 +00:00 committed by Gerrit Code Review
commit a0c1cd87a6
2 changed files with 25 additions and 0 deletions

View File

@ -210,6 +210,10 @@ class TestCase(testtools.TestCase):
sql_connection=CONF.database.connection)
self.useFixture(_DB_CACHE)
# NOTE(blk-u): WarningsFixture must be after the Database fixture
# because sqlalchemy-migrate messes with the warnings filters.
self.useFixture(cinder_fixtures.WarningsFixture())
# NOTE(danms): Make sure to reset us back to non-remote objects
# for each test to avoid interactions. Also, backup the object
# registry.

View File

@ -18,6 +18,7 @@ from __future__ import absolute_import
import logging as std_logging
import os
import warnings
import fixtures
@ -110,3 +111,23 @@ class StandardLogging(fixtures.Fixture):
self.useFixture(
fixtures.MonkeyPatch('oslo_log.log.setup', fake_logging_setup))
class WarningsFixture(fixtures.Fixture):
"""Filters out warnings during test runs."""
def setUp(self):
super(WarningsFixture, self).setUp()
# NOTE(sdague): Make deprecation warnings only happen once. Otherwise
# this gets kind of crazy given the way that upstream python libs use
# this.
warnings.simplefilter('once', DeprecationWarning)
# NOTE(sdague): this remains an unresolved item around the way
# forward on is_admin, the deprecation is definitely really premature.
warnings.filterwarnings(
'ignore',
message='Policy enforcement is depending on the value of is_admin.'
' This key is deprecated. Please update your policy '
'file to use the standard policy values.')
self.addCleanup(warnings.resetwarnings)