-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Warn on pytest.mark.skip("sys.version_info < (3, 6)")
(should use skipif
)
#12582
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
Comments
Word. It almost makes me think the problem is the API. Having It's too bad they're both under the Going back to your warning proposal, I'm a bit confused... how would a warning condition containing Also, wouldn't condition (1) require running every reason for every Notes
|
Oops, warning proposal was indeed nonsensical, edited. I don't want to reconsider the whole API design here, just a small improvement on it. But yeah, the confusability certainly doesn't help! |
Perhaps a ruff rule might help aswell |
A ruff rule might help pytest, but the implicit concern here is about the potential hundreds of other projects whose test files may contain the same silent mistake. A ruff rule in the pytest repo won't help them. 😀 |
@ferdnyc I was suggesting a upstream ruff rule that's the default in future |
Oh! Oh, that's a neat idea, yeah. (Edit: GitHub really needs to add 💡 to its paltry set of comment reactions.) |
Is there a reason not to deprecate Furthermore, would it make sense to deprecate
This would be backwards compatible (ie: PS: Technically, additional logic, we could maintain the order of, |
Personally I'd like to deprecate string conditions, but then again, they're in quite wide use and that'd cause quite an amount of code churn. -1 to |
I'd recommend a soft deprecation, If we support lambda expressions instead, it's probably doable to supply a ruff auto-fix thats Safe |
I don't think a broader API change is worth the churn at the moment; we can ship this small tweak and move on to the many other open issues 🙂 |
Yes to the soft deprecation. I should have clarified in regards to the deprecation—I meant adding a deprecation warning—at least until next major release. As for the lambda, It's still not clear to me why this would be necessary, aside from lazy evaluation. It should be noted that wrapping these conditionals in lambda would impact performance (though negligible in most use cases). I was considering passing conditionals into As a side note, we could pass all
Though this feature would only be useful as an augmentation to I'm not advocating for this particular approach, and personally don't think it's worth the added complexity, but I do think it's worth discussion (ie: perhaps most appropriate as a 3rd party pytest plugin.). |
String conditionals are able to use extra values like the pytest configuration and a few more things |
I was wondering if there was a use case for lazy evaluation—seems like there is. |
Sounds good. Is this something you're working on? Otherwise, I can create PR. |
See #12172 (comment) 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:
skip
and a mark named e.g.skipif
also exists - for any name, not justskip
, andreason
or first-positional-argument string is (1) a valid expression forast.parse
, and (2) it's not just a trivialname
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')")
.The text was updated successfully, but these errors were encountered: