Skip to content

Commit

Permalink
Merge pull request #1960 from nicoddemus/skip-module-level-doc
Browse files Browse the repository at this point in the history
Add a note about pytest.skip not being allowed at module level
  • Loading branch information
The-Compiler authored Sep 26, 2016
2 parents 8dc497b + 19766ef commit b071fdc
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions doc/en/skipping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ imperatively, in test or setup code::
# or
pytest.skip("unsupported configuration")

Note that calling ``pytest.skip`` at the module level
is not allowed since pytest 3.0. If you are upgrading
and ``pytest.skip`` was being used at the module level, you can set a
``pytestmark`` variable:

.. code-block:: python
# before pytest 3.0
pytest.skip('skipping all tests because of reasons')
# after pytest 3.0
pytestmark = pytest.mark.skip('skipping all tests because of reasons')
``pytestmark`` applies a mark or list of marks to all tests in a module.


Skipping on a missing import dependency
--------------------------------------------------
Expand Down Expand Up @@ -371,3 +385,27 @@ The equivalent with "boolean conditions" is::
imported before pytest's argument parsing takes place. For example,
``conftest.py`` files are imported before command line parsing and thus
``config.getvalue()`` will not execute correctly.


Summary
-------

Here's a quick guide on how to skip tests in a module in different situations:

1. Skip all tests in a module unconditionally:

.. code-block:: python
pytestmark = pytest.mark.skip('all tests still WIP')
2. Skip all tests in a module based on some condition:

.. code-block:: python
pytestmark = pytest.mark.skipif(sys.platform == 'win32', 'tests for linux only')
3. Skip all tests in a module if some import is missing:

.. code-block:: python
pexpect = pytest.importorskip('pexpect')

0 comments on commit b071fdc

Please sign in to comment.