Skip to content

Commit

Permalink
Add fixture to only emit DeprecationWarning once
Browse files Browse the repository at this point in the history
We have a ton of DeprecationWarning messages in our unit test runs.
Most of these are out of our control from third party libs. This
adds a WarningsFixture to limit warning output to once per test
run, getting rid of >700 warnings in our logs.

Borrowed heavily from Id8d8866baaf64721fda2b6b2e8358db18920c8ba and
I5eaf953b6a2b0a3efe215f776aa048433b192e90 in Nova.

Change-Id: I2250d4bad1b1f7d1f83c175a5e2b124f02ec9212
  • Loading branch information
stmcginnis committed Nov 21, 2017
1 parent ab5dfc0 commit bdae03a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cinder/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ def setUp(self):
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.
Expand Down
21 changes: 21 additions & 0 deletions cinder/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import logging as std_logging
import os
import warnings

import fixtures

Expand Down Expand Up @@ -110,3 +111,23 @@ def fake_logging_setup(*args):

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)

0 comments on commit bdae03a

Please sign in to comment.