Add WarningsFixture to only emit DeprecationWarning once in a test run
The nova unit test console output can be flooded with deprecation warnings from dependent libraries, this change makes it so they are only logged once. It's worth noting that Keystone has an alternative implementation where they filter deprecation warnings and only error out if they are coming from Keystone code. See commit 9ae6ffe8a. Partial-Bug: #1407736 Co-authored-by: Sean Dague <sean@dague.net> Change-Id: Id8d8866baaf64721fda2b6b2e8358db18920c8ba
This commit is contained in:
parent
42f33e5581
commit
e9c92d68b1
@ -198,6 +198,7 @@ class TestCase(testtools.TestCase):
|
||||
self.useFixture(nova_fixtures.OutputStreamCapture())
|
||||
|
||||
self.useFixture(nova_fixtures.StandardLogging())
|
||||
self.useFixture(nova_fixtures.WarningsFixture())
|
||||
|
||||
# NOTE(sdague): because of the way we were using the lock
|
||||
# wrapper we eneded up with a lot of tests that started
|
||||
|
@ -21,6 +21,7 @@ import gettext
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
import warnings
|
||||
|
||||
import fixtures
|
||||
from oslo.config import cfg
|
||||
@ -235,3 +236,15 @@ class RPCFixture(fixtures.Fixture):
|
||||
self.messaging_conf.transport_driver = 'fake'
|
||||
self.useFixture(self.messaging_conf)
|
||||
rpc.init(CONF)
|
||||
|
||||
|
||||
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)
|
||||
self.addCleanup(warnings.resetwarnings)
|
||||
|
Loading…
Reference in New Issue
Block a user