diff --git a/nibabel/__init__.py b/nibabel/__init__.py index aa90540b8..c389c603f 100644 --- a/nibabel/__init__.py +++ b/nibabel/__init__.py @@ -170,10 +170,7 @@ def bench(label=None, verbose=1, extra_argv=None): code : ExitCode Returns the result of running the tests as a ``pytest.ExitCode`` enum """ - try: - from importlib.resources import as_file, files - except ImportError: - from importlib_resources import as_file, files + from importlib.resources import as_file, files args = [] if extra_argv is not None: diff --git a/nibabel/conftest.py b/nibabel/conftest.py index b16a832f2..1d7389e86 100644 --- a/nibabel/conftest.py +++ b/nibabel/conftest.py @@ -10,10 +10,7 @@ @pytest.fixture(scope='session', autouse=True) def legacy_printoptions(): - from packaging.version import Version - - if Version(np.__version__) >= Version('1.22'): - np.set_printoptions(legacy='1.21') + np.set_printoptions(legacy='1.21') @pytest.fixture @@ -24,7 +21,7 @@ def max_digits(): orig_max_str_digits = sys.get_int_max_str_digits() yield sys.set_int_max_str_digits sys.set_int_max_str_digits(orig_max_str_digits) - except AttributeError: # pragma: no cover + except AttributeError: # PY310 # pragma: no cover # Nothing to do for versions of Python that lack these methods # They were added as DoS protection in Python 3.11 and backported to # some other versions. diff --git a/nibabel/tests/test_init.py b/nibabel/tests/test_init.py index d54f55053..d339c4e26 100644 --- a/nibabel/tests/test_init.py +++ b/nibabel/tests/test_init.py @@ -1,14 +1,10 @@ import pathlib import unittest +from importlib.resources import files from unittest import mock import pytest -try: - from importlib.resources import files -except ImportError: - from importlib_resources import files - import nibabel as nib