Repository navigation
Warn when pytest.mark.skip reason looks like a condition #15252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LuanaPBueno
wants to merge
2
commits into
pytest-dev:main
Choose a base branch
from
LuanaPBueno:warn-skip-condition-reason
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pytest now warns when the reason given to ``pytest.mark.skip`` looks like a condition (for example ``"sys.platform == 'win32'"``), since ``pytest.mark.skipif`` was probably intended. |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I favor a simpler approach: rather than checking the contents of the expression, just reject those which contain only letters/space/dot:
it seems to me that this better captures the core "looks like valid english" issue, and is very simple.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review, Zac! I like the idea of making it simpler. I have two small concerns about the regex, though:
'[A-z]' also matches a few non-letter characters ('[', '', ']', '^', '_'), since they come between 'Z' and 'a' in ASCII. I think '[A-Za-z .]' is what we want here.
Checking only for letters, spaces and dots would also warn on many common reasons that are just normal sentences, for example:
I worry this could add a lot of noise to existing test suites, which is the same problem I ran into with the original rule from the issue.
One middle ground could be to keep the regex approach but allow more characters that are common in normal English, like '[\w\s.,'#:!?-]+'. That way digits, commas and apostrophes are fine, while things like '==', '<' or parentheses still warn. But I'm happy to go with whichever you prefer, either that or keeping the 'ast' version. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These examples all raise an error in
ast.parse(...)- my proposal is that we should warn on anything which parses as Python, unless it consists only of letters, space, and dot.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried your approach locally, and it works well, except for one case: test_warnings.py has @pytest.mark.skip("issue #13485"), which parses as Python (# starts a comment), so it warns and that test fails. Should I ignore everything after #, or change that skip reason? I’ll push once we decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd change it, eg to "see issue #...."; one case seems like acceptable collateral for a simple rule.