]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable all deprecation warnings for test runs
authorIhar Hrachyshka <ihrachys@redhat.com>
Tue, 9 Jun 2015 08:57:29 +0000 (10:57 +0200)
committerIhar Hrachyshka <ihrachys@redhat.com>
Tue, 9 Jun 2015 10:03:45 +0000 (12:03 +0200)
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
neutron/tests/tools.py

index 7b18901044be19827c4ce5bf1981b5d1fe13c6bf..a9cf779ee8b57e450a78d0ef1dbb8072e493459b 100644 (file)
@@ -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:
index fd53793fee699d682b99491226dfdf518e0871ef..40c308d59966bf697eb149c92d9e696ab0203863 100644 (file)
@@ -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.