Skip to content

Commit f31aba5

Browse files
committed
TEST: Add setup/teardown to try to catch warnings properly [WIP]
1 parent 798fc4e commit f31aba5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

nibabel/tests/test_nifti1.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ class TestNifti1PairHeader(tana.TestAnalyzeHeader, tspm.HeaderScalingMixin):
8383
np.longcomplex))
8484
tana.add_intp(supported_np_types)
8585

86+
def setUp(self):
87+
# Add warning filters for duration of test case
88+
self._wctx = warnings.catch_warnings()
89+
self._wctx.__enter__()
90+
warnings.filterwarnings('ignore', 'get_zooms', FutureWarning)
91+
warnings.filterwarnings('ignore', 'Unknown (spatial|time) units',
92+
UserWarning)
93+
94+
def tearDown(self):
95+
# Restore warning filters
96+
self._wctx.__exit__()
97+
8698
def test_empty(self):
8799
tana.TestAnalyzeHeader.test_empty(self)
88100
hdr = self.header_class()
@@ -765,6 +777,18 @@ class TestNifti1Pair(tana.TestAnalyzeImage, tspm.ImageScalingMixin):
765777
image_class = Nifti1Pair
766778
supported_np_types = TestNifti1PairHeader.supported_np_types
767779

780+
def setUp(self):
781+
# Add warning filters for duration of test case
782+
self._wctx = warnings.catch_warnings()
783+
self._wctx.__enter__()
784+
warnings.filterwarnings('ignore', 'get_zooms', FutureWarning)
785+
warnings.filterwarnings('ignore', 'Unknown (spatial|time) units',
786+
UserWarning)
787+
788+
def tearDown(self):
789+
# Restore warning filters
790+
self._wctx.__exit__()
791+
768792
def test_int64_warning(self):
769793
# Verify that initializing with (u)int64 data and no
770794
# header/dtype info produces a warning

0 commit comments

Comments
 (0)