Skip to content

Commit e28afc5

Browse files
committed
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: I63f57980e01f472a25821790610f0836f1882a7f Signed-off-by: Stephen Finucane <[email protected]>
1 parent 79436a8 commit e28afc5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

nova/tests/fixtures/nova.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,9 @@ class WarningsFixture(fixtures.Fixture):
780780

781781
def setUp(self):
782782
super(WarningsFixture, self).setUp()
783+
784+
self._original_warning_filters = warnings.filters[:]
785+
783786
# NOTE(sdague): Make deprecation warnings only happen once. Otherwise
784787
# this gets kind of crazy given the way that upstream python libs use
785788
# this.
@@ -836,7 +839,10 @@ def setUp(self):
836839
message='Implicit coercion of SELECT and textual SELECT .*',
837840
category=sqla_exc.SADeprecationWarning)
838841

839-
self.addCleanup(warnings.resetwarnings)
842+
self.addCleanup(self._reset_warning_filters)
843+
844+
def _reset_warning_filters(self):
845+
warnings.filters[:] = self._original_warning_filters
840846

841847

842848
class ConfPatcher(fixtures.Fixture):

0 commit comments

Comments
 (0)