In a recent pytest training, a participant mistakenly added strict=True to a skipif marker in a file instead of the xfail one, and that was surprised that nothing happened. Indeed, pytest is happy with:
import pytest
@pytest.mark.skipif(True, strict=True, reason="")
def test_x():
pass
while pytest.mark.skip does validate the arguments:
@pytest.mark.skip(strict=True, reason="")
def test_y():
pass
[...]
.venv/lib/python3.14/site-packages/_pytest/skipping.py:249: in pytest_runtest_setup
skipped = evaluate_skip_marks(item)
^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <Function test_y>
def evaluate_skip_marks(item: Item) -> Skip | None:
"""Evaluate skip and skipif marks on item, returning Skip if triggered."""
for mark in item.iter_markers(name="skipif"):
if "condition" not in mark.kwargs:
conditions = mark.args
else:
conditions = (mark.kwargs["condition"],)
# Unconditional.
if not conditions:
reason = mark.kwargs.get("reason", "")
return Skip(reason)
# If any of the conditions are true.
for condition in conditions:
result, reason = evaluate_condition(item, mark, condition)
if result:
return Skip(reason)
for mark in item.iter_markers(name="skip"):
try:
return Skip(*mark.args, **mark.kwargs)
except TypeError as e:
> raise TypeError(str(e) + " - maybe you meant pytest.mark.skipif?") from None
E TypeError: Skip.__init__() got an unexpected keyword argument 'strict' - maybe you meant pytest.mark.skipif?
.venv/lib/python3.14/site-packages/_pytest/skipping.py:192: TypeError
In a recent pytest training, a participant mistakenly added
strict=Trueto askipifmarker in a file instead of thexfailone, and that was surprised that nothing happened. Indeed, pytest is happy with:while
pytest.mark.skipdoes validate the arguments: