-
Is it correct that custom markers are expected to be type-hinted by the user (me) who is using pytest? Given code like this, @mark.real_http_call
class Test_Some_Service:
pass I am getting an error from Pyright on the
Or is it already handled/typed by pytest somehow but pyright is not recognizing it like in this issue? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The situation is a bit complicated. pytest provides real proper typing for its own built-in marks, but cannot provide them for custom marks, at the moment. Nonetheless, there is still typing for the generic case, specifically (showing only the pertinent parts) Markable = TypeVar("Markable", bound=Union[Callable[..., object], type])
@attr.s(init=False, auto_attribs=True)
class MarkDecorator:
# Type ignored because the overloads overlap with an incompatible
# return type. Not much we can do about that. Thankfully mypy picks
# the first match so it works out even if we break the rules.
@overload
def __call__(self, arg: Markable) -> Markable: # type: ignore[misc]
pass
@overload
def __call__(self, *args: object, **kwargs: object) -> "MarkDecorator":
pass This works for mypy, but maybe pyright doesn't like some of these tricks (quite understandable...). |
Beta Was this translation helpful? Give feedback.
-
Once I updated |
Beta Was this translation helpful? Give feedback.
Once I updated
pytest
to 6.2.2 the warnings were gone.