Merge "Add WarningsFixture to only emit DeprecationWarning once in a test run"
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user