Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

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

Open
nonamethanks opened this issue Mar 2, 2023 · 0 comments

Comments

@nonamethanks
Copy link

nonamethanks commented Mar 2, 2023

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant