Skip to content

Commit 6cec414

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

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

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

768+
def setUp(self):
769+
# Add warning filters for duration of test case
770+
self._wctx = warnings.catch_warnings()
771+
self._wctx.__enter__()
772+
warnings.filterwarnings('ignore', 'get_zooms', FutureWarning)
773+
warnings.filterwarnings('ignore', 'Unknown (spatial|time) units',
774+
UserWarning)
775+
776+
def tearDown(self):
777+
# Restore warning filters
778+
self._wctx.__exit__()
779+
756780
def test_none_qsform(self):
757781
# Check that affine gets set to q/sform if header is None
758782
img_klass = self.image_class

0 commit comments

Comments
 (0)