@@ -94,6 +94,38 @@ def _skip_if_not_us_locale():
94
94
return True
95
95
96
96
97
+ def skip_if_no (package , min_version = None ):
98
+ """
99
+ Generic function to help skip test functions when required packages are not
100
+ present on the testing system.
101
+
102
+ Intended for use as a decorator, this function will wrap the decorated
103
+ function with a pytest ``skip_if`` mark. During a pytest test suite
104
+ execution, that mark will attempt to import the specified ``package`` and
105
+ optionally ensure it meets the ``min_version``. If the import and version
106
+ check are unsuccessful, then the decorated function will be skipped.
107
+
108
+ Parameters
109
+ ----------
110
+ package: str
111
+ The name of the package required by the decorated function
112
+ min_version: str or None, default None
113
+ Optional minimum version of the package required by the decorated
114
+ function
115
+
116
+ Returns
117
+ -------
118
+ decorated_func: function
119
+ The decorated function wrapped within a pytest ``skip_if`` mark
120
+ """
121
+ def decorated_func (func ):
122
+ return pytest .mark .skipif (
123
+ not safe_import (package , min_version = min_version ),
124
+ reason = "Could not import '{}'" .format (package )
125
+ )(func )
126
+ return decorated_func
127
+
128
+
97
129
skip_if_no_mpl = pytest .mark .skipif (_skip_if_no_mpl (),
98
130
reason = "Missing matplotlib dependency" )
99
131
skip_if_mpl_1_5 = pytest .mark .skipif (_skip_if_mpl_1_5 (),
0 commit comments