Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/_pytest/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ def evaluate_skip_marks(item: Item) -> Skip | None:
else:
conditions = (mark.kwargs["condition"],)

for invalid_kwarg in set(mark.kwargs) - {"condition", "reason"}:
raise TypeError(
f"pytest.mark.skipif() got an unexpected keyword argument {invalid_kwarg!r}"
)

# Unconditional.
if not conditions:
reason = mark.kwargs.get("reason", "")
Expand Down
18 changes: 17 additions & 1 deletion testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_marked_one_arg_with_reason(self, pytester: Pytester) -> None:
item = pytester.getitem(
"""
import pytest
@pytest.mark.skipif("hasattr(os, 'sep')", attr=2, reason="hello world")
@pytest.mark.skipif("hasattr(os, 'sep')", reason="hello world")
def test_func():
pass
"""
Expand Down Expand Up @@ -882,6 +882,22 @@ def test_hello():


class TestSkipif:
def test_skipif_invalid_kwarg(self, pytester: Pytester) -> None:
p = pytester.makepyfile(
"""
import pytest
@pytest.mark.skipif(True, strict=True, reason="")
def test_func():
pass
"""
)
result = pytester.runpytest(p)
result.stdout.fnmatch_lines(
[
"*TypeError: pytest.mark.skipif() got an unexpected keyword argument 'strict'*",
]
)

def test_skipif_conditional(self, pytester: Pytester) -> None:
item = pytester.getitem(
"""
Expand Down