Skip to content

Commit 6f4c2aa

Browse files
committed
TEST: Add setup/teardown to try to catch warnings properly [WIP]
1 parent f1b4ab0 commit 6f4c2aa

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
@@ -80,6 +80,18 @@ class TestNifti1PairHeader(tana.TestAnalyzeHeader, tspm.HeaderScalingMixin):
8080
np.longcomplex))
8181
tana.add_intp(supported_np_types)
8282

83+
def setUp(self):
84+
# Add warning filters for duration of test case
85+
self._wctx = warnings.catch_warnings()
86+
self._wctx.__enter__()
87+
warnings.filterwarnings('ignore', 'get_zooms', FutureWarning)
88+
warnings.filterwarnings('ignore', 'Unknown (spatial|time) units',
89+
UserWarning)
90+
91+
def tearDown(self):
92+
# Restore warning filters
93+
self._wctx.__exit__()
94+
8395
def test_empty(self):
8496
tana.TestAnalyzeHeader.test_empty(self)
8597
hdr = self.header_class()
@@ -762,6 +774,18 @@ class TestNifti1Pair(tana.TestAnalyzeImage, tspm.ImageScalingMixin):
762774
image_class = Nifti1Pair
763775
supported_np_types = TestNifti1PairHeader.supported_np_types
764776

777+
def setUp(self):
778+
# Add warning filters for duration of test case
779+
self._wctx = warnings.catch_warnings()
780+
self._wctx.__enter__()
781+
warnings.filterwarnings('ignore', 'get_zooms', FutureWarning)
782+
warnings.filterwarnings('ignore', 'Unknown (spatial|time) units',
783+
UserWarning)
784+
785+
def tearDown(self):
786+
# Restore warning filters
787+
self._wctx.__exit__()
788+
765789
def test_none_qsform(self):
766790
# Check that affine gets set to q/sform if header is None
767791
img_klass = self.image_class

0 commit comments

Comments
 (0)