Skip to content

Commit 111d640

Browse files
authored
Merge pull request #2873 from stephenfin/doc/skipping-entire-files
doc: Include collector config in the skip doc
2 parents 734c435 + 383239c commit 111d640

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

doc/en/example/pythoncollection.rst

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,23 @@ You can always peek at the collection tree without running tests like this::
175175
176176
======= no tests ran in 0.12 seconds ========
177177

178-
customizing test collection to find all .py files
179-
---------------------------------------------------------
178+
.. _customizing-test-collection:
180179

181-
.. regendoc:wipe
180+
Customizing test collection
181+
---------------------------
182182

183-
You can easily instruct ``pytest`` to discover tests from every python file::
183+
.. regendoc:wipe
184184
185+
You can easily instruct ``pytest`` to discover tests from every Python file::
185186

186187
# content of pytest.ini
187188
[pytest]
188189
python_files = *.py
189190

190-
However, many projects will have a ``setup.py`` which they don't want to be imported. Moreover, there may files only importable by a specific python version.
191-
For such cases you can dynamically define files to be ignored by listing
192-
them in a ``conftest.py`` file::
191+
However, many projects will have a ``setup.py`` which they don't want to be
192+
imported. Moreover, there may files only importable by a specific python
193+
version. For such cases you can dynamically define files to be ignored by
194+
listing them in a ``conftest.py`` file::
193195

194196
# content of conftest.py
195197
import sys
@@ -198,7 +200,7 @@ them in a ``conftest.py`` file::
198200
if sys.version_info[0] > 2:
199201
collect_ignore.append("pkg/module_py2.py")
200202

201-
And then if you have a module file like this::
203+
and then if you have a module file like this::
202204

203205
# content of pkg/module_py2.py
204206
def test_only_on_python2():
@@ -207,13 +209,13 @@ And then if you have a module file like this::
207209
except Exception, e:
208210
pass
209211

210-
and a setup.py dummy file like this::
212+
and a ``setup.py`` dummy file like this::
211213

212214
# content of setup.py
213215
0/0 # will raise exception if imported
214216

215-
then a pytest run on Python2 will find the one test and will leave out the
216-
setup.py file::
217+
If you run with a Python 2 interpreter then you will find the one test and will
218+
leave out the ``setup.py`` file::
217219

218220
#$ pytest --collect-only
219221
====== test session starts ======
@@ -225,13 +227,13 @@ setup.py file::
225227

226228
====== no tests ran in 0.04 seconds ======
227229

228-
If you run with a Python3 interpreter both the one test and the setup.py file
229-
will be left out::
230+
If you run with a Python 3 interpreter both the one test and the ``setup.py``
231+
file will be left out::
230232

231233
$ pytest --collect-only
232234
======= test session starts ========
233235
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y
234236
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
235237
collected 0 items
236-
238+
237239
======= no tests ran in 0.12 seconds ========

doc/en/skipping.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.. _skipping:
44

55
Skip and xfail: dealing with tests that cannot succeed
6-
=====================================================================
6+
======================================================
77

88
You can mark test functions that cannot be run on certain platforms
99
or that you expect to fail so pytest can deal with them accordingly and
@@ -142,6 +142,16 @@ will be skipped if any of the skip conditions is true.
142142
.. _`whole class- or module level`: mark.html#scoped-marking
143143

144144

145+
Skipping files or directories
146+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147+
148+
Sometimes you may need to skip an entire file or directory, for example if the
149+
tests rely on Python version-specific features or contain code that you do not
150+
wish pytest to run. In this case, you must exclude the files and directories
151+
from collection. Refer to :ref:`customizing-test-collection` for more
152+
information.
153+
154+
145155
Skipping on a missing import dependency
146156
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147157

0 commit comments

Comments
 (0)