@@ -99,36 +99,40 @@ def _skip_if_no_scipy():
99
99
100
100
def skip_if_no (package , min_version = None ):
101
101
"""
102
- Generic function to help skip test functions when required packages are not
102
+ Generic function to help skip tests when required packages are not
103
103
present on the testing system.
104
104
105
- Intended for use as a decorator, this function will wrap the decorated
106
- function with a pytest ``skip_if`` mark. During a pytest test suite
107
- execution, that mark will attempt to import the specified ``package`` and
108
- optionally ensure it meets the ``min_version``. If the import and version
109
- check are unsuccessful, then the decorated function will be skipped.
105
+ This function returns a pytest mark with a skip condition that will be
106
+ evaluated during test collection. An attempt will be made to import the
107
+ specified ``package`` and optionally ensure it meets the ``min_version``
108
+
109
+ The mark can be used as either a decorator for a test function or to be
110
+ applied to parameters in pytest.mark.parametrize calls or parametrized
111
+ fixtures.
112
+
113
+ If the import and version check are unsuccessful, then the test function
114
+ (or test case when used in conjunction with parametrization) will be
115
+ skipped.
110
116
111
117
Parameters
112
118
----------
113
119
package: str
114
- The name of the package required by the decorated function
120
+ The name of the required package.
115
121
min_version: str or None, default None
116
- Optional minimum version of the package required by the decorated
117
- function
122
+ Optional minimum version of the package.
118
123
119
124
Returns
120
125
-------
121
- decorated_func: function
122
- The decorated function wrapped within a pytest ``skip_if`` mark
126
+ _pytest.mark.structures.MarkDecorator
127
+ a pytest.mark.skipif to use as either a test decorator or a
128
+ parametrization mark.
123
129
"""
124
- def decorated_func (func ):
125
- msg = "Could not import '{}'" .format (package )
126
- if min_version :
127
- msg += " satisfying a min_version of {}" .format (min_version )
128
- return pytest .mark .skipif (
129
- not safe_import (package , min_version = min_version ), reason = msg
130
- )(func )
131
- return decorated_func
130
+ msg = "Could not import '{}'" .format (package )
131
+ if min_version :
132
+ msg += " satisfying a min_version of {}" .format (min_version )
133
+ return pytest .mark .skipif (
134
+ not safe_import (package , min_version = min_version ), reason = msg
135
+ )
132
136
133
137
134
138
skip_if_no_mpl = pytest .mark .skipif (_skip_if_no_mpl (),
0 commit comments