pytest-dev / pytest-dev/pytest

Warn on `pytest.mark.skip("sys.version_info < (3, 6)")` (should use `skipif`)

Open
#12,582 14 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: marks type: enhancement
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. skip and a mark named e.g. skipif also exists - for any name, not just skip, and
  • the reason or first-positional-argument string is (1) a valid expression for ast.parse, and (2) it's not just a trivial name expression (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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.