Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update documentation example of pytest.skip(allow_module_level=True)
  • Loading branch information
georgeyk committed Oct 3, 2017
commit 59f66933cd9468eec3dc67714f1b686f8dfb1c39
7 changes: 4 additions & 3 deletions doc/en/skipping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ by calling the ``pytest.skip(reason)`` function:
It is also possible to skip the whole module using
``pytest.skip(reason, allow_module_level=True)`` at the module level:


.. code-block:: python

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do wonder if there is a better example for this (thats not looking like a skipif marker or a importorskip would already solve

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe using the use case from previous discussion ? Something like:

if not pytest.config.getoption('--custom-flag'):
    pytest.skip('--custom-flag is missing, skipping tests', allow_module_level=True)

if not enabled_platform_edge_cases():
pytest.skip("unsupported platform", allow_module_level=True)
import pytest

if not pytest.config.getoption("--custom-flag"):
pytest.skip("--custom-flag is missing, skipping tests", allow_module_level=True)

The imperative method is useful when it is not possible to evaluate the skip condition
during import time.
Expand Down