Merge "Add fixture to only emit DeprecationWarning once"
This commit is contained in:
commit
a0c1cd87a6
@ -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.
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user