pytest-dev / pytest-dev/pytest
Warn on `pytest.mark.skip("sys.version_info < (3, 6)")` (should use `skipif`)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
See https://github.com/pytest-dev/pytest/pull/12172#discussion_r1667357437 for some cases where this bit us; at time of writing there are at least three cases in Pytest's own tests where this is biting us. I think it's pretty unlikely that we're the only people ever to make this mistake, so let's add a warning that would have caught it.
I propose that the warning should trigger if:
- the mark is named e.g.
skipand a mark named e.g.skipifalso exists - for any name, not justskip, and - the
reasonor first-positional-argument string is (1) a valid expression forast.parse, and (2) it's not just a trivialnameexpression (i.e. contains a comparison and/or a call)
Based on some quick searches, this would not have any false alarms (and so I think there would be very few after shipping), and it would catch things like pytest.mark.skip("sys.platform.startswith('win')").
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked pull-request discussion and inspect the Pytest tests where string conditions are passed to skip marks. Trace how skip and skipif marks are processed, then review the proposed ast.parse conditions and warning cases. Done means the warning catches nontrivial expression strings used with skip when skipif is present, without false alarms for trivial names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100