pytest-dev / pytest-dev/pytest

support plugins as a class

Open
#11,300 7 comments 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.