summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-11-19 09:12:10 +0000
committerStephen Finucane <stephenfin@redhat.com>2021-11-19 09:12:10 +0000
commita0db55dcea5caba74fd6d177038f517413b9ac69 (patch)
tree62a9f89a826a124d1646f736a5f67945b0d8fea8
parent2fbda1b67193280d2663886031a1152ef6f2927a (diff)
downloadoslo-db-a0db55dcea5caba74fd6d177038f517413b9ac69.tar.gz
tests: Restore - don't reset - warning filters
There are more various warning filters pre-configured in a typical Python environment, including a few from third-party libraries such as requests [1][2] and urllib3 [3] as well as stdlib [4]. Our fixture to configure warnings, 'WarningsFixture', called 'warnings.resetwarnings' which *reset* all the warning filters [5]. This is clearly not something we want to do, and resulted in tests puking warnings after the initial test run. Resolve this by backing up the existing warning filters before applying the filter, and then *restoring* this original list of warning filters after the test run. [1] https://github.com/psf/requests/blob/v2.26.0/requests/__init__.py#L127 [2] https://github.com/psf/requests/blob/v2.26.0/requests/__init__.py#L152 [3] https://github.com/urllib3/urllib3/blob/1.26.7/src/urllib3/__init__.py#L68-L78 [4] https://docs.python.org/3.8/library/warnings.html#default-warning-filter [5] https://docs.python.org/3.8/library/warnings.html#warnings.resetwarnings Change-Id: Ie74dad3f20002dd26fa9760c9ba452c4a40186c5 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
-rw-r--r--oslo_db/tests/fixtures.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/oslo_db/tests/fixtures.py b/oslo_db/tests/fixtures.py
index 521639c..9b26d62 100644
--- a/oslo_db/tests/fixtures.py
+++ b/oslo_db/tests/fixtures.py
@@ -21,6 +21,9 @@ class WarningsFixture(fixtures.Fixture):
def setUp(self):
super().setUp()
+
+ self._original_warning_filters = warnings.filters[:]
+
# Make deprecation warnings only happen once to avoid spamming
warnings.simplefilter('once', DeprecationWarning)
@@ -74,4 +77,7 @@ class WarningsFixture(fixtures.Fixture):
module='migrate',
category=sqla_exc.SADeprecationWarning)
- self.addCleanup(warnings.resetwarnings)
+ self.addCleanup(self._reset_warning_filters)
+
+ def _reset_warning_filters(self):
+ warnings.filters[:] = self._original_warning_filters