-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
support plugins as a class #11300
Comments
No base class is needed,any object instance can be registered as a class |
As for type checking, as Plugins can add new hooks,a mypy plugin is needed in any case |
@RonnyPfannschmidt A thin interface would likely help the majority of use cases of typechecking and API discovery with minimal effort. A mypy plugin, while not neccissarily a bad idea, sounds like a much harder task with many more considerations to make. from typing import Protocol
class Plugin(Protocol):
def pytest_runtestloop(self, session: Session):
...
# etc |
I'm somewhat lukewarm on this as well, for two reasons:
|
Personally, knowing that my types are correct is 100x more beneficial than the convenience of defining my code as a module over a class. And this would just be an option, the suggestion is not to force it. |
That wasn't my point. Of course it's helpful if you know it exists and want to use it — but something most likely not benefiting the majority of current plugin users needs to be weighted up against the additional development effort (and, most likely, future issues with things getting out of sync) of having to duplicate everything. Then again, it looks like pluggy already supports declaring hook specifications in a class, so perhaps pytest could indeed declare a FWIW, I'm not sure using a Additionally, and this might make this entire thing completely impossible anyways, hook arguments can be left out. You might say you're okay with just also declaring the unused arguments in exchange of getting type checking, but sometimes this is done deliberately for backwards compatibility. For example, various hooks have two different path arguments, and implementing something like: def pytest_ignore_collect(collection_path: pathlib.Path, path: py.path.local, config: pytest.Config) -> bool | None:
# do something with collection_path, ignore the rest
pass while working fine currently, might start raising a deprecation warning at some point in the future. |
Based on how pluggy works that's likely going to require some type of white elephant to make it sensible As far as I am concerned a mypy plugin is most likely easier than the hack's needed for plugin spec's to stay peformant But it would be nice for someone to disprove me |
What's the problem this feature will solve?
currently, there is no way to type check your hook functions:
Describe the solution you'd like
expose a base class for plugins to extend, so they can be defined like so:
Alternative Solutions
Additional context
The text was updated successfully, but these errors were encountered: