fix: validate keyword arguments for pytest.mark.skipif (#14839) - #14871
Closed
The-habib wants to merge 2 commits into
Closed
fix: validate keyword arguments for pytest.mark.skipif (#14839)#14871The-habib wants to merge 2 commits into
The-habib wants to merge 2 commits into
Conversation
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds keyword argument validation for
pytest.mark.skipif. Previously, any unsupported keyword argument passed to@pytest.mark.skipif(such asstrict=True) was silently ignored. Now,evaluate_skip_marksvalidates keyword arguments and raises aTypeErrorwhen unexpected arguments are passed (including a helpful hint whenstrictis passed).Closes #14839
Problem
When a user mistakenly writes
@pytest.mark.skipif(True, strict=True, reason="")instead ofpytest.mark.xfail,pytest.mark.skipifsilently ignoresstrict=True. In contrast,pytest.mark.skipvalidates its arguments.Solution
In
src/_pytest/skipping.py(evaluate_skip_marks), validate thatmark.kwargsonly contains"condition"and"reason". If unexpected keyword arguments are present, raise aTypeError. Ifstrictis passed, append a helpful hint- maybe you meant pytest.mark.xfail?.Testing
test_marked_one_arg_with_reasonintesting/test_skipping.py.test_marked_skipif_unexpected_kwargandtest_marked_skipif_strict_kwargintesting/test_skipping.py.testing/test_skipping.pyandtesting/test_mark.pypass.changelog/14839.bugfix.rst.AUTHORS.