Skip to content

pytest.mark.skipif silently ignores extra keyword args #14839

Description

@The-Compiler

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: marksrelated to marks, either the general marks or builtin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions