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
2727
2828.. autofunction :: _pytest.outcomes.skip(msg, [allow_module_level=False])
2929
30+ .. _`pytest.importorskip ref` :
31+
3032pytest.importorskip
3133~~~~~~~~~~~~~~~~~~~
3234
Original file line number Diff line number Diff line change @@ -179,16 +179,15 @@ information.
179179Skipping on a missing import dependency
180180~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181181
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.
184184
185185.. code-block :: python
186186
187187 docutils = pytest.importorskip(" docutils" )
188188
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:
192191
193192.. code-block :: python
194193
Original file line number Diff line number Diff line change @@ -143,14 +143,21 @@ def xfail(reason=""):
143143
144144
145145def 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.
148148
149149 :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")
154161 """
155162 import warnings
156163
You can’t perform that action at this time.
0 commit comments