Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,14 @@ pytest.mark.skipif

Skip a test function if a condition is ``True``.

.. py:function:: pytest.mark.skipif(condition, *, reason=None)
.. py:function:: pytest.mark.skipif(condition, *conditions, reason=None)

:type condition: bool or str
:param condition: ``True/False`` if the condition should be skipped or a :ref:`condition string <string conditions>`.
:type conditions: bool or str
:param conditions:
Additional conditions, evaluated the same way as ``condition``. The test is
skipped if *any* of the conditions evaluate to ``True``.
:keyword str reason: Reason why the test function is being skipped.


Expand Down Expand Up @@ -266,12 +270,15 @@ pytest.mark.xfail

Marks a test function as *expected to fail*.

.. py:function:: pytest.mark.xfail(condition=True, *, reason=None, raises=None, run=True, strict=strict_xfail)
.. py:function:: pytest.mark.xfail(condition=True, *conditions, reason=None, raises=None, run=True, strict=strict_xfail)

:keyword Union[bool, str] condition:
Condition for marking the test function as xfail (``True/False`` or a
:ref:`condition string <string conditions>`). If a ``bool``, you also have
to specify ``reason`` (see :ref:`condition string <string conditions>`).
:keyword Union[bool, str] conditions:
Additional conditions, evaluated the same way as ``condition``. The test is
marked as xfail if *any* of the conditions evaluate to ``True``.
:keyword str reason:
Reason why the test function is marked as xfail.
:keyword raises:
Expand Down
37 changes: 37 additions & 0 deletions testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,43 @@ def test_func():
assert skipped
assert skipped.reason == "hello world"

def test_marked_multiple_args_skipif(self, pytester: Pytester) -> None:
item = pytester.getitem(
"""
import pytest
@pytest.mark.skipif(False, True, reason="hello world")
def test_func():
pass
"""
)
skipped = evaluate_skip_marks(item)
assert skipped
assert skipped.reason == "hello world"

def test_marked_multiple_args_skipif_all_false(self, pytester: Pytester) -> None:
item = pytester.getitem(
"""
import pytest
@pytest.mark.skipif(False, False, reason="hello world")
def test_func():
pass
"""
)
assert evaluate_skip_marks(item) is None

def test_marked_multiple_args_xfail(self, pytester: Pytester) -> None:
item = pytester.getitem(
"""
import pytest
@pytest.mark.xfail(False, True, reason="hello world")
def test_func():
pass
"""
)
xfailed = evaluate_xfail_marks(item)
assert xfailed
assert xfailed.reason == "hello world"

def test_marked_one_arg_twice(self, pytester: Pytester) -> None:
lines = [
"""@pytest.mark.skipif("not hasattr(os, 'murks')")""",
Expand Down