Debian Codegraph @

oslo_db/tests/fixtures.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 import warnings
14
15 import fixtures
16 from sqlalchemy import exc as sqla_exc
17
18
19 class WarningsFixture(fixtures.Fixture):
20 """Filters out warnings during test runs."""
21
22 def setUp(self):
23 super().setUp()
24
25 self._original_warning_filters = warnings.filters[:]
26
27 # Enable deprecation warnings
28
29 warnings.simplefilter('once', DeprecationWarning)
30
31 # Except for things we've deprecated but are still testing until
32 # removal
33
34 warnings.filterwarnings(
35 'ignore',
36 category=DeprecationWarning,
37 module='oslo_db',
38 )
39
40 # Enable generic warnings to ensure we're not doing anything odd
41
42 warnings.filterwarnings(
43 'error',
44 category=sqla_exc.SAWarning,
45 )
46
47 # Enable deprecation warnings to capture upcoming SQLAlchemy changes
48
49 warnings.filterwarnings(
50 'error',
51 category=sqla_exc.SADeprecationWarning,
52 )
53
54 self.addCleanup(self._reset_warning_filters)
55
56 def _reset_warning_filters(self):
57 warnings.filters[:] = self._original_warning_filters