pytest-dev / pytest-dev/pytest
`pytest.mark.skipif` silently ignores extra keyword args
Open
Nobody has claimed this yet.
topic: marks
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in _pytest/skipping.py at evaluate_skip_marks and compare how skipif and skip marker arguments are handled. Add a regression test covering an unexpected keyword argument on skipif, then run the relevant skipping tests and confirm the marker no longer silently accepts it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100