fix(marks): reject unknown kwargs in skip/skipif (#14839) - #14869
Closed
Carltonkenny wants to merge 2 commits into
Closed
fix(marks): reject unknown kwargs in skip/skipif (#14839)#14869Carltonkenny wants to merge 2 commits into
Carltonkenny wants to merge 2 commits into
Conversation
Previously, pytest.mark.skip(strict=True, reason='x') and
pytest.mark.skipif(True, strict=True, reason='x') were silently
accepted because MarkDecorator.__call__ takes **kwargs and stores
them in the resulting Mark. This masks user mistakes (e.g. typing
strict on a skipif when they meant xfail).
Add a per-builtin-mark kwarg allow-list (skip: {reason};
skipif: {reason}; xfail: {condition, reason, run, raises, strict})
validated at MarkDecorator.with_args time. Custom (user-registered)
marks are not validated because their schema is unknown.
Fixes pytest-dev#14839.
for more information, see https://pre-commit.ci
Member
|
clank |
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
Fix pytest#14839:
pytest.mark.skipif(strict=True, reason=...)andpytest.mark.skip(strict=True, reason=...)are silently accepted instead of raising a clear error.In a pytest training, a participant mistakenly added
strict=Trueto askipifmarker in a file instead of thexfailone, and was surprised that nothing happened.Before
After
Implementation
Added a per-builtin-mark kwarg allow-list (
skip: {reason},skipif: {reason},xfail: {condition, reason, run, raises, strict}) validated inMarkDecorator.with_args. Custom (user-registered) marks are not validatedbecause we cannot know their parameter schema.
Tests
TestBuiltinMarkKwargsValidation.Fixes #14839.