File tree Expand file tree Collapse file tree 3 files changed +19
-11
lines changed Expand file tree Collapse file tree 3 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ pytest.skip
27
27
28
28
.. autofunction :: _pytest.outcomes.skip(msg, [allow_module_level=False])
29
29
30
+ .. _`pytest.importorskip ref` :
31
+
30
32
pytest.importorskip
31
33
~~~~~~~~~~~~~~~~~~~
32
34
Original file line number Diff line number Diff line change @@ -179,16 +179,15 @@ information.
179
179
Skipping on a missing import dependency
180
180
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181
181
182
- You can use the following helper at module level
183
- or within a test or test setup function:
182
+ You can skip tests on a missing import by using :ref: ` pytest.importorskip ref `
183
+ at module level or within a test or test setup function.
184
184
185
185
.. code-block :: python
186
186
187
187
docutils = pytest.importorskip(" docutils" )
188
188
189
- If ``docutils `` cannot be imported here, this will lead to a
190
- skip outcome of the test. You can also skip based on the
191
- version number of a library:
189
+ If ``docutils `` cannot be imported here, this will lead to a skip outcome of
190
+ the test. You can also skip based on the version number of a library:
192
191
193
192
.. code-block :: python
194
193
Original file line number Diff line number Diff line change @@ -143,14 +143,21 @@ def xfail(reason=""):
143
143
144
144
145
145
def importorskip (modname , minversion = None , reason = None ):
146
- """Imports and returns the requested module ``modname``, or skip the current test
147
- if the module cannot be imported.
146
+ """Imports and returns the requested module ``modname``, or skip the
147
+ current test if the module cannot be imported.
148
148
149
149
:param str modname: the name of the module to import
150
- :param str minversion: if given, the imported module ``__version__`` attribute must be
151
- at least this minimal version, otherwise the test is still skipped.
152
- :param str reason: if given, this reason is shown as the message when the module
153
- cannot be imported.
150
+ :param str minversion: if given, the imported module ``__version__``
151
+ attribute must be at least this minimal version, otherwise the test is
152
+ still skipped.
153
+ :param str reason: if given, this reason is shown as the message when the
154
+ module cannot be imported.
155
+ :returns: The imported module. This should be assigned to its canonical
156
+ name.
157
+
158
+ Example::
159
+
160
+ docutils = pytest.importorskip("docutils")
154
161
"""
155
162
import warnings
156
163
You can’t perform that action at this time.
0 commit comments