From f1e03aadaee63b18aa7d23bbe999dae6d1b96b0a Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 19 Apr 2023 11:57:38 +0100 Subject: [PATCH] tests: Enable warnings Add the warnings fixture so we can catch deprecation warnings earlier. Change-Id: I37a349237470beb60240d0b6c208aa75f2a075ac Signed-off-by: Stephen Finucane --- barbican/tests/database_utils.py | 3 ++- barbican/tests/fixture.py | 17 +++++++++++++++++ barbican/tests/utils.py | 10 ++++++---- functionaltests/api/base.py | 9 ++++++--- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/barbican/tests/database_utils.py b/barbican/tests/database_utils.py index 1dd1af4a5..4a7311662 100644 --- a/barbican/tests/database_utils.py +++ b/barbican/tests/database_utils.py @@ -275,8 +275,9 @@ class RepositoryTestCase(oslotest.BaseTestCase): hard to debug 'Broken Pipe' errors could result! """ def setUp(self): - super(RepositoryTestCase, self).setUp() + super().setUp() self.useFixture(barbican_fixture.StandardLogging()) + self.useFixture(barbican_fixture.WarningsFixture()) setup_in_memory_db() # Clean up once tests are completed. diff --git a/barbican/tests/fixture.py b/barbican/tests/fixture.py index cea582782..6de5331bb 100644 --- a/barbican/tests/fixture.py +++ b/barbican/tests/fixture.py @@ -12,6 +12,7 @@ import logging as std_logging import os +import warnings import fixtures from oslo_db.sqlalchemy import session @@ -162,3 +163,19 @@ class StandardLogging(fixtures.Fixture): self.useFixture( fixtures.MonkeyPatch('oslo_log.log.setup', fake_logging_setup)) + + +class WarningsFixture(fixtures.Fixture): + """Filters out warnings during test runs.""" + + def setUp(self): + super().setUp() + + self._original_warning_filters = warnings.filters[:] + + warnings.simplefilter('once', DeprecationWarning) + + self.addCleanup(self._reset_warning_filters) + + def _reset_warning_filters(self): + warnings.filters[:] = self._original_warning_filters diff --git a/barbican/tests/utils.py b/barbican/tests/utils.py index ab533def6..07ccbb616 100644 --- a/barbican/tests/utils.py +++ b/barbican/tests/utils.py @@ -73,8 +73,9 @@ class BarbicanAPIBaseTestCase(oslotest.BaseTestCase): return context def setUp(self): - super(BarbicanAPIBaseTestCase, self).setUp() + super().setUp() self.useFixture(barbican_fixture.StandardLogging()) + self.useFixture(barbican_fixture.WarningsFixture()) # Make sure we have a test db and session to work with database_utils.setup_in_memory_db() @@ -94,22 +95,23 @@ class BarbicanAPIBaseTestCase(oslotest.BaseTestCase): def tearDown(self): database_utils.in_memory_cleanup() - super(BarbicanAPIBaseTestCase, self).tearDown() + super().tearDown() class BaseTestCase(oslotest.BaseTestCase): def setUp(self): - super(BaseTestCase, self).setUp() + super().setUp() self.useFixture(barbican_fixture.StandardLogging()) + self.useFixture(barbican_fixture.WarningsFixture()) self.order_id = 'order1234' self.external_project_id = 'keystone1234' self.request_id = 'request1234' def tearDown(self): - super(BaseTestCase, self).tearDown() ss_conf = config.get_module_config('secretstore') ss_conf.clear_override("enable_multiple_secret_stores", group='secretstore') + super().tearDown() class MockModelRepositoryMixin(object): diff --git a/functionaltests/api/base.py b/functionaltests/api/base.py index 1a67d0e02..33770ce47 100644 --- a/functionaltests/api/base.py +++ b/functionaltests/api/base.py @@ -22,6 +22,7 @@ from oslo_utils import uuidutils import oslotest.base as oslotest from testtools import testcase +from barbican.tests import fixture as barbican_fixture from barbican.tests import utils from functionaltests.common import client from functionaltests.common import config @@ -48,11 +49,11 @@ class TestCase(oslotest.BaseTestCase): @classmethod def setUpClass(cls): cls.LOG = logging.getLogger(cls._get_full_case_name()) - super(TestCase, cls).setUpClass() + super().setUpClass() def setUp(self): self.LOG.info('Starting: %s', self._testMethodName) - super(TestCase, self).setUp() + super().setUp() self.client = client.BarbicanClient() @@ -74,8 +75,10 @@ class TestCase(oslotest.BaseTestCase): format=self.log_format, level=logging.DEBUG)) + self.useFixture(barbican_fixture.WarningsFixture()) + def tearDown(self): - super(TestCase, self).tearDown() + super().tearDown() self.LOG.info('Finished: %s\n', self._testMethodName) @classmethod