From 6b13cc5275df53c765c450d570521c425c3345d9 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Tue, 9 Jun 2015 10:57:29 +0200 Subject: [PATCH] Enable all deprecation warnings for test runs We would like to catch all deprecation warnings during test runs to be notified in advance about potential problems with next library releases we depend on. Change-Id: I876d8c4de88618b01898ab537a44920789d8178e --- neutron/tests/base.py | 4 ++++ neutron/tests/tools.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/neutron/tests/base.py b/neutron/tests/base.py index 7b1890104..a9cf779ee 100644 --- a/neutron/tests/base.py +++ b/neutron/tests/base.py @@ -45,6 +45,7 @@ from neutron import manager from neutron import policy from neutron.tests import fake_notifier from neutron.tests import post_mortem_debug +from neutron.tests import tools CONF = cfg.CONF @@ -126,6 +127,9 @@ class DietTestCase(testtools.TestCase): self.addOnException(post_mortem_debug.get_exception_handler( debugger)) + # Make sure we see all relevant deprecation warnings when running tests + self.useFixture(tools.WarningsFixture()) + if bool_from_env('OS_DEBUG'): _level = std_logging.DEBUG else: diff --git a/neutron/tests/tools.py b/neutron/tests/tools.py index fd53793fe..40c308d59 100644 --- a/neutron/tests/tools.py +++ b/neutron/tests/tools.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import warnings + import fixtures import six @@ -49,6 +51,21 @@ class AttributeMapMemento(fixtures.Fixture): attributes.RESOURCE_ATTRIBUTE_MAP = self.contents_backup +class WarningsFixture(fixtures.Fixture): + """Filters out warnings during test runs.""" + + warning_types = ( + DeprecationWarning, PendingDeprecationWarning, ImportWarning + ) + + def setUp(self): + super(WarningsFixture, self).setUp() + for wtype in self.warning_types: + warnings.filterwarnings( + "always", category=wtype, module='^neutron\\.') + self.addCleanup(warnings.resetwarnings) + + """setup_mock_calls and verify_mock_calls are convenient methods to setup a sequence of mock calls. -- 2.45.2