diff --git a/CPAC/generate_motion_statistics/generate_motion_statistics.py b/CPAC/generate_motion_statistics/generate_motion_statistics.py index e72ecbef3f..9ba248e180 100644 --- a/CPAC/generate_motion_statistics/generate_motion_statistics.py +++ b/CPAC/generate_motion_statistics/generate_motion_statistics.py @@ -24,13 +24,12 @@ from typing import Optional import numpy as np import nibabel as nb -#import pytest -from CPAC.pipeline import nipype_pipeline_engine as pe +from nipype.interfaces.afni.base import (AFNICommand, AFNICommandInputSpec) +from nipype.interfaces.base import (TraitedSpec, traits, File) import nipype.interfaces.utility as util +from CPAC.pipeline import nipype_pipeline_engine as pe from CPAC.utils.interfaces.function import Function - -from nipype.interfaces.afni.base import (AFNICommand, AFNICommandInputSpec) -from nipype.interfaces.base import (TraitedSpec, traits, isdefined, File) +from CPAC.utils.pytest import skipif def motion_power_statistics(name='motion_stats', @@ -352,8 +351,8 @@ def calculate_FD_P(in_file): return out_file -#@pytest.mark.skipif(sys.version_info < (3, 10), -# reason="Test requires Python 3.10 or higher") +@skipif(sys.version_info < (3, 10), + reason="Test requires Python 3.10 or higher") def calculate_FD_J(in_file: str, calc_from: Literal['affine', 'rms'], center: Optional[np.ndarray] = None) -> str: """ diff --git a/CPAC/utils/pytest.py b/CPAC/utils/pytest.py new file mode 100644 index 0000000000..4ea9a46b0d --- /dev/null +++ b/CPAC/utils/pytest.py @@ -0,0 +1,32 @@ +# Copyright (C) 2023 C-PAC Developers + +# This file is part of C-PAC. + +# C-PAC is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. + +# C-PAC is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with C-PAC. If not, see . +"""Utilities for Pytest integration""" +try: + import pytest + HAVE_PYTEST = True +except ImportError: + HAVE_PYTEST = False + + +def skipif(condition, reason): + """Skip test if we have Pytest, ignore test entirely if not""" + def decorator(func): + """Skip test if we have Pytest""" + if HAVE_PYTEST: + return pytest.mark.skipif(condition, reason)(func) + return func # return undecorated function + return decorator # return conditionally decorated function