Merge "Add WarningsFixture to only emit DeprecationWarning once in a test run"

This commit is contained in:
Jenkins
2015-01-08 09:13:47 +00:00
committed by Gerrit Code Review
2 changed files with 14 additions and 0 deletions

View File

@@ -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

View File

@@ -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)