Skip to content

TEST: Prefer vanilla unittest.skip* to pytest skips #883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 1 addition & 57 deletions .azure-pipelines/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,73 +41,17 @@ jobs:
cd for_testing
cp ../.coveragerc .
nosetests --with-doctest --with-coverage --cover-package nibabel nibabel ^
-I test_array_sequence ^
-I test_tractogram ^
-I test_api_validators ^
-I test_arrayproxy ^
-I test_arraywriters ^
-I test_batteryrunners ^
-I test_brikhead ^
-I test_casting ^
-I test_cifti2io_axes ^
-I test_cifti2io_header ^
-I test_data ^
-I test_deprecated ^
-I test_deprecator ^
-I test_dicomwrappers ^
-I test_dft ^
-I test_ecat ^
-I test_ecat_data ^
-I test_endiancodes ^
-I test_environment ^
-I test_euler ^
-I test_filebasedimages ^
-I test_filehandles ^
-I test_fileholders ^
-I test_filename_parser ^
-I test_files_interface ^
-I test_fileslice ^
-I test_fileutils ^
-I test_floating ^
-I test_funcs ^
-I test_giftiio ^
-I test_h5py_compat ^
-I test_image_api ^
-I test_image_load_save ^
-I test_image_types ^
-I test_imageclasses ^
-I test_imageglobals ^
-I test_io ^
-I test_keywordonly ^
-I test_loadsave ^
-I test_minc1 ^
-I test_minc2 ^
-I test_minc2_data ^
-I test_mriutils ^
-I test_netcdf ^
-I test_nibabel_data ^
-I test_nifti1 ^
-I test_nifti2 ^
-I test_openers ^
-I test_optpkg ^
-I test_orientations ^
-I test_parrec ^
-I test_parrec_data ^
-I test_pkg_info ^
-I test_processing ^
-I test_proxy_api ^
-I test_quaternions ^
-I test_recoder ^
-I test_remmovalschedule ^
-I test_round_trip ^
-I test_rstutils ^
-I test_scaling ^
-I test_wrapstruct ^
-I test_io ^
-I test_scripts ^
-I test_spaces ^
-I test_testing ^
-I test_wrapstruct
-I test_testing
displayName: 'Nose tests'
condition: and(succeeded(), eq(variables['CHECK_TYPE'], 'nosetests'))
- script: |
Expand Down
58 changes: 1 addition & 57 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,73 +134,17 @@ script:
cd for_testing
cp ../.coveragerc .
nosetests --with-doctest --with-coverage --cover-package nibabel nibabel \
-I test_array_sequence \
-I test_tractogram \
-I test_api_validators \
-I test_arrayproxy \
-I test_arraywriters \
-I test_batteryrunners \
-I test_brikhead \
-I test_casting \
-I test_cifti2io_axes \
-I test_cifti2io_header \
-I test_data \
-I test_deprecated \
-I test_deprecator \
-I test_dicomwrappers \
-I test_dft \
-I test_ecat \
-I test_ecat_data \
-I test_endiancodes \
-I test_environment \
-I test_euler \
-I test_filebasedimages \
-I test_filehandles \
-I test_fileholders \
-I test_filename_parser \
-I test_files_interface \
-I test_fileslice \
-I test_fileutils \
-I test_floating \
-I test_funcs \
-I test_giftiio \
-I test_h5py_compat \
-I test_image_api \
-I test_image_load_save \
-I test_image_types \
-I test_imageclasses \
-I test_imageglobals \
-I test_io \
-I test_keywordonly \
-I test_loadsave \
-I test_minc1 \
-I test_minc2 \
-I test_minc2_data \
-I test_mriutils \
-I test_netcdf \
-I test_nibabel_data \
-I test_nifti1 \
-I test_nifti2 \
-I test_openers \
-I test_optpkg \
-I test_orientations \
-I test_parrec \
-I test_parrec_data \
-I test_pkg_info \
-I test_processing \
-I test_proxy_api \
-I test_quaternions \
-I test_recoder \
-I test_remmovalschedule \
-I test_round_trip \
-I test_rstutils \
-I test_scaling \
-I test_wrapstruct \
-I test_io \
-I test_scripts \
-I test_spaces \
-I test_testing \
-I test_wrapstruct
-I test_testing
elif [ "${CHECK_TYPE}" == "test" ]; then
# Change into an innocuous directory and find tests from installation
mkdir for_testing
Expand Down
7 changes: 3 additions & 4 deletions nibabel/freesurfer/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import hashlib
import warnings


from ...tmpdirs import InTemporaryDirectory


import unittest
import pytest
import numpy as np
from numpy.testing import assert_allclose, assert_array_equal
Expand All @@ -36,8 +35,8 @@
data_path = pjoin(nib_data, 'nitest-freesurfer', DATA_SDIR)
have_freesurfer = isdir(data_path)

freesurfer_test = pytest.mark.skipif(not have_freesurfer,
reason='cannot find freesurfer {0} directory'.format(DATA_SDIR))
freesurfer_test = unittest.skipUnless(have_freesurfer,
'cannot find freesurfer {0} directory'.format(DATA_SDIR))

def _hash_file_content(fname):
hasher = hashlib.md5()
Expand Down
19 changes: 3 additions & 16 deletions nibabel/testing_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@
import sys
import warnings
from pkg_resources import resource_filename
from os.path import dirname, abspath, join as pjoin

import unittest

import numpy as np
from numpy.testing import assert_array_equal, assert_warns
from numpy.testing import dec
skipif = dec.skipif
slow = dec.slow
from numpy.testing import assert_array_equal

from ..deprecated import deprecate_with_version as _deprecate_with_version
from .np_features import memmap_after_ufunc
from .helpers import bytesio_filemap, bytesio_round_trip, assert_data_similar

Expand Down Expand Up @@ -63,7 +58,7 @@ def assert_allclose_safely(a, b, match_nans=True, rtol=1e-5, atol=1e-8):
a, b = np.broadcast_arrays(a, b)
if match_nans:
nans = np.isnan(a)
np.testing.assert_array_equal(nans, np.isnan(b))
assert_array_equal(nans, np.isnan(b))
to_test = ~nans
else:
to_test = np.ones(a.shape, dtype=bool)
Expand Down Expand Up @@ -199,20 +194,12 @@ class suppress_warnings(error_warnings):
filter = 'ignore'


@_deprecate_with_version('catch_warn_reset is deprecated; use '
'nibabel.testing.clear_and_catch_warnings.',
since='2.1.0', until='3.0.0')
class catch_warn_reset(clear_and_catch_warnings):
pass


EXTRA_SET = os.environ.get('NIPY_EXTRA_TESTS', '').split(',')


def runif_extra_has(test_str):
"""Decorator checks to see if NIPY_EXTRA_TESTS env var contains test_str"""
return skipif(test_str not in EXTRA_SET,
"Skip {0} tests.".format(test_str))
return unittest.skipUnless(test_str in EXTRA_SET, "Skip {0} tests.".format(test_str))


def assert_arr_dict_equal(dict1, dict2):
Expand Down
10 changes: 5 additions & 5 deletions nibabel/tests/nibabel_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from os import environ, listdir
from os.path import dirname, realpath, join as pjoin, isdir, exists

import pytest
import unittest


def get_nibabel_data():
Expand Down Expand Up @@ -39,11 +39,11 @@ def needs_nibabel_data(subdir=None):
"""
nibabel_data = get_nibabel_data()
if nibabel_data == '':
return pytest.mark.skipif(True, reason="Need nibabel-data directory for this test")
return unittest.skip("Need nibabel-data directory for this test")
if subdir is None:
return pytest.mark.skipif(False, reason="Don't skip")
return lambda x: x
required_path = pjoin(nibabel_data, subdir)
# Path should not be empty (as is the case for not-updated submodules)
have_files = exists(required_path) and len(listdir(required_path)) > 0
return pytest.mark.skipif(not have_files,
reason="Need files in {0} for these tests".format(required_path))
return unittest.skipUnless(have_files,
"Need files in {0} for these tests".format(required_path))
13 changes: 8 additions & 5 deletions nibabel/tests/test_dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .. import dft
from .. import nifti1

import unittest
import pytest

# Shield optional package imports
Expand All @@ -22,10 +23,12 @@
data_dir = pjoin(dirname(__file__), 'data')


pytestmark = [
pytest.mark.skipif(os.name == 'nt', reason='FUSE not available for windows, skipping dft tests'),
pytest.mark.skipif(not have_dicom, reason='Need pydicom for dft tests, skipping')
]
def setUpModule():
if os.name == 'nt':
raise unittest.SkipTest('FUSE not available for windows, skipping dft tests')
if not have_dicom:
raise unittest.SkipTest('Need pydicom for dft tests, skipping')


def test_init():
dft.clear_cache()
Expand Down Expand Up @@ -76,7 +79,7 @@ def test_storage_instance():
pass


@pytest.mark.skipif(not have_pil, reason='could not import PIL.Image')
@unittest.skipUnless(have_pil, 'could not import PIL.Image')
def test_png():
studies = dft.get_studies(data_dir)
data = studies[0].series[0].as_png()
Expand Down
9 changes: 7 additions & 2 deletions nibabel/tests/test_image_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from ..spatialimages import SpatialImage
from .. import minc1, minc2, parrec, brikhead

import unittest
import pytest

from numpy.testing import assert_almost_equal, assert_array_equal, assert_warns, assert_allclose
Expand Down Expand Up @@ -121,7 +122,7 @@ def validate_filenames(self, imaker, params):
# Validate the filename, file_map interface

if not self.can_save:
pytest.skip()
raise unittest.SkipTest
img = imaker()
img.set_data_dtype(np.float32) # to avoid rounding in load / save
# Make sure the object does not have a file_map
Expand Down Expand Up @@ -706,8 +707,12 @@ class TestMinc1API(ImageHeaderAPI):
example_images = MINC1_EXAMPLE_IMAGES


@pytest.mark.skipif(not have_h5py, reason="Need h5py for Minc2 tests")
class TestMinc2API(TestMinc1API):

def __init__(self):
if not have_h5py:
raise unittest.SkipTest('Need h5py for these tests')

klass = image_maker = Minc2Image
loader = minc2.load
example_images = MINC2_EXAMPLE_IMAGES
Expand Down
3 changes: 2 additions & 1 deletion nibabel/tests/test_parrec_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from .nibabel_data import get_nibabel_data, needs_nibabel_data

import unittest
import pytest
from numpy.testing import assert_almost_equal

Expand Down Expand Up @@ -60,7 +61,7 @@ def test_fieldmap():
fieldmap_nii = pjoin(BALLS, 'NIFTI', 'fieldmap.nii.gz')
load(fieldmap_par)
top_load(fieldmap_nii)
raise pytest.skip('Fieldmap remains puzzling')
raise unittest.SkipTest('Fieldmap remains puzzling')


@needs_nibabel_data('parrec_oblique')
Expand Down
6 changes: 3 additions & 3 deletions nibabel/tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
voxel_sizes)
from nibabel.eulerangles import euler2mat

from numpy.testing import (assert_almost_equal,
assert_array_equal)
from numpy.testing import assert_almost_equal, assert_array_equal
import unittest
import pytest

from nibabel.tests.test_spaces import assert_all_in, get_outspace_params
from nibabel.testing import assert_allclose_safely

needs_scipy = pytest.mark.skipif(not have_scipy, reason='These tests need scipy')
needs_scipy = unittest.skipUnless(have_scipy, 'These tests need scipy')

DATA_DIR = pjoin(dirname(__file__), 'data')

Expand Down
3 changes: 2 additions & 1 deletion nibabel/tests/test_proxy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

from ..arrayproxy import ArrayProxy, is_proxy

import unittest
import pytest
from numpy.testing import assert_almost_equal, assert_array_equal, assert_allclose

Expand Down Expand Up @@ -428,7 +429,7 @@ def eg_func():
arr_out=arr_out))

def validate_header_isolated(self, pmaker, params):
raise pytest.skip('ECAT header does not support dtype get')
raise unittest.SkipTest('ECAT header does not support dtype get')


class TestPARRECAPI(_TestProxyAPI):
Expand Down
3 changes: 2 additions & 1 deletion nibabel/tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ..loadsave import load
from ..orientations import flip_axis, aff2axcodes, inv_ornt_aff

import unittest
import pytest
from numpy.testing import assert_almost_equal

Expand Down Expand Up @@ -120,7 +121,7 @@ def test_nib_ls(args):
check_nib_ls_example4d(*args)


@pytest.mark.skipif(not load_small_file(), reason="can't load the small.mnc file")
@unittest.skipUnless(load_small_file(), "Can't load the small.mnc file")
@script_test
def test_nib_ls_multiple():
# verify that correctly lists/formats for multiple files
Expand Down
Loading