-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Type annotate pytest.mark.{skip,skipif,xfail,parametrize} #7379
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
Conversation
c39eee6
to
00f6a7e
Compare
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! I agree the workaround is worth it, and only affects typing, so it shouldn't introduce unexpected problems.
FTR there is some relation with #5424.
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.
Can users opt out of this, as this introduces partial mark incompatible typing
As currently written, they can't. Mypy doesn't support It is possible for the user to "cheat" by using e.g. |
What's that exactly, is it related to I ask because this is in line with the work started in #5424, where one of the outcomes (at least in my mind) is that we would not generate the builtin marks dynamically anymore, but would have proper signatures declared, very similar to what we have here. |
@bluetech i believe its possible to type this correct as long as the actual return type supports a overridden call and a override |
Let me clarify the partial mark comment. There is a minor issue there but it's mostly a red herring, I didn't understand it quite right. This patch only affects the mark-generator ( So the difference is, that for the builtin marks, the
(1) I think is fine, shouldn't do that. If for some reason want to provide extra args, can add them as a second step after the mark is created, e.g. (2) is actually mostly a non-issue because out of all of pytest's builtin marks, only @RonnyPfannschmidt mentioned |
BTW there are a few builtin marks I forgot (looking at
|
Thanks for elaborating the details, with that my misunderstanding is cleared |
00f6a7e
to
0188cf2
Compare
0188cf2
to
b3fb5a2
Compare
I added typing also for |
These marks are some of the most used user-facing APIs in pytest, but because they are marks, which accept any arguments and are evaluated dynamically, there aren't any places to type them like regular functions.
This PR does a little cheating by special-casing them inside
MarkGenerator
. This is a gross breach of abstraction and other bad stuff, in particular it is not generalizable to 3rd-party marks (at least, if accessed throughpytest.mark
). However, due to the pervasiveness of these marks I think it is worth it, until/if we find a better solution.I typed the marks as complete functions, i.e. building "partial" marks (like
get_empty_parameterset_mark
in the diff does) is not allowed. I think that's fine for these marks at least.