pytest-dev / pytest-dev/pytest
support plugins as a class
Open
Nobody has claimed this yet.
topic: typing
type: proposal
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
What's the problem this feature will solve?
currently, there is no way to type check your hook functions:
from pytest import Item
def pytest_runtestloop(session: Item): # no type error, it should be Session
...
Describe the solution you'd like
expose a base class for plugins to extend, so they can be defined like so:
from typing_extensions import override
from pytest import Plugin
class SomePlugin(Plugin):
@override
def pytest_runtestloop(self, session: Item): # type error: signature does not match base method
...
Alternative Solutions
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pytest_runtestloop hook shown in the issue and review how pytest currently defines and exposes plugin hooks. Determine the scope of a Plugin base class and its hook signatures, then verify that a mismatched session annotation is rejected by a type checker while valid plugin methods remain supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100