darrenburns / ward

Ward is a modern test framework for Python with a focus on productivity and readability.
https://ward.readthedocs.io
MIT License
1.21k stars 53 forks source link

Argument(s) {'results', 'exit_code'} are declared in the hookimpl but can not be found in the hookspec #369

Open nonamethanks opened 1 year ago

nonamethanks commented 1 year ago

The example for after_session hooks from the documentation doesn't work. https://ward.readthedocs.io/en/latest/guide/plugins.html

from typing import Optional, List

from rich.console import RenderResult, Console, ConsoleOptions, ConsoleRenderable
from rich.panel import Panel
from rich.text import Text
from ward.config import Config
from ward.hooks import hook
from ward.models import ExitCode
from ward.testing import TestResult

@hook
def after_session(
    config: Config, results: List[TestResult], exit_code: ExitCode
) -> Optional[ConsoleRenderable]:
    return SummaryPanel(test_results)

class SummaryPanel:
    def __init__(self, results: List[TestResult]):
        self.results = results

    @property
    def time_taken(self):
        return sum(r.test.timer.duration for r in self.results)

    def __rich_console__(
        self, console: Console, console_options: ConsoleOptions
    ) -> RenderResult:
        yield Panel(
            Text(f"Hello from `after_session`! We ran {len(self.results)} tests!")
        )

Even after fixing the stray "test_results" in after_session, this raises

hookimpl definition: after_session(config: ward.config.Config, results: List[ward.testing.TestResult], exit_code: ward.models.ExitCode) -> Optional[rich.console.ConsoleRenderable]
Argument(s) {'results', 'exit_code'} are declared in the hookimpl but can not be found in the hookspec