Skip to content

Commit 4d7dd36

Browse files
committed
MAINT: Use a more general _test_state structure for setup/teardown
1 parent d5e90dc commit 4d7dd36

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

nibabel/__init__.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,27 @@
3636
"""
3737

3838
# Package-wide test setup and teardown
39-
# Numpy changed print options in 1.14; we can update docstrings and remove
40-
# these when our minimum for building docs exceeds that
41-
_save_printopts = None
39+
_test_states = {
40+
# Numpy changed print options in 1.14; we can update docstrings and remove
41+
# these when our minimum for building docs exceeds that
42+
'legacy_printopt': None,
43+
}
4244

4345
def setup_package():
4446
""" Set numpy print style to legacy="1.13" for newer versions of numpy """
45-
import nibabel as nb
4647
import numpy as np
4748
from distutils.version import LooseVersion
48-
if nb._save_printopts is None:
49-
nb._save_printopts = np.get_printoptions().get('legacy')
5049
if LooseVersion(np.__version__) >= LooseVersion('1.14'):
50+
if _test_states.get('legacy_printopt') is None:
51+
_test_states['legacy_printopt'] = np.get_printoptions().get('legacy')
5152
np.set_printoptions(legacy="1.13")
5253

5354
def teardown_package():
5455
""" Reset print options when tests finish """
55-
import nibabel as nb
5656
import numpy as np
57-
if nb._save_printopts is not None:
58-
np.set_printoptions(legacy=nb._save_printopts)
59-
nb._save_printopts = None
57+
if _test_states.get('legacy_printopt') is not None:
58+
np.set_printoptions(legacy=_test_states['legacy_printopt'])
59+
_test_states['legacy_printopt'] = None
6060

6161

6262
# module imports

0 commit comments

Comments
 (0)