@@ -24,7 +24,9 @@ def test_foo():
24
24
For more information, refer to the ``pytest`` documentation on ``skipif``.
25
25
"""
26
26
import locale
27
+ from typing import Optional
27
28
29
+ from _pytest .mark .structures import MarkDecorator
28
30
import pytest
29
31
30
32
from pandas .compat import is_platform_32bit , is_platform_windows
@@ -97,38 +99,45 @@ def _skip_if_no_scipy():
97
99
safe_import ('scipy.signal' ))
98
100
99
101
100
- def skip_if_no (package , min_version = None ):
102
+ def skip_if_no (
103
+ package : str ,
104
+ min_version : Optional [str ] = None
105
+ ) -> MarkDecorator :
101
106
"""
102
- Generic function to help skip test functions when required packages are not
107
+ Generic function to help skip tests when required packages are not
103
108
present on the testing system.
104
109
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.
110
+ This function returns a pytest mark with a skip condition that will be
111
+ evaluated during test collection. An attempt will be made to import the
112
+ specified ``package`` and optionally ensure it meets the ``min_version``
113
+
114
+ The mark can be used as either a decorator for a test function or to be
115
+ applied to parameters in pytest.mark.parametrize calls or parametrized
116
+ fixtures.
117
+
118
+ If the import and version check are unsuccessful, then the test function
119
+ (or test case when used in conjunction with parametrization) will be
120
+ skipped.
110
121
111
122
Parameters
112
123
----------
113
124
package: str
114
- The name of the package required by the decorated function
125
+ The name of the required package.
115
126
min_version: str or None, default None
116
- Optional minimum version of the package required by the decorated
117
- function
127
+ Optional minimum version of the package.
118
128
119
129
Returns
120
130
-------
121
- decorated_func: function
122
- The decorated function wrapped within a pytest ``skip_if`` mark
131
+ _pytest.mark.structures.MarkDecorator
132
+ a pytest.mark.skipif to use as either a test decorator or a
133
+ parametrization mark.
123
134
"""
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
135
+ msg = "Could not import '{}'" .format (package )
136
+ if min_version :
137
+ msg += " satisfying a min_version of {}" .format (min_version )
138
+ return pytest .mark .skipif (
139
+ not safe_import (package , min_version = min_version ), reason = msg
140
+ )
132
141
133
142
134
143
skip_if_no_mpl = pytest .mark .skipif (_skip_if_no_mpl (),
0 commit comments