diff --git a/src/GherkinParser/Library.py b/src/GherkinParser/Library.py index fb881bf..ab6b72f 100644 --- a/src/GherkinParser/Library.py +++ b/src/GherkinParser/Library.py @@ -49,7 +49,7 @@ def call_hooks(self, events: Union[str, Tuple[str, ...]], *args: Any, **kwargs: finally: self._in_call_hooks = False - def yield_hooks(self, events: Union[str, Tuple[str, ...]], *args: Any, **kwargs: Any) -> Iterator[str]: + def yield_hooks(self, event_type: str, events: Union[str, Tuple[str, ...]], *args: Any, **kwargs: Any) -> Iterator[str]: if isinstance(events, str): events = (events,) ctx = EXECUTION_CONTEXTS.current @@ -57,7 +57,7 @@ def yield_hooks(self, events: Union[str, Tuple[str, ...]], *args: Any, **kwargs: *([(v.name, l) for l in v.keywords] for v in ctx.namespace._kw_store.resources.values()), *([(v.name, l) for l in v.keywords] for v in ctx.namespace._kw_store.libraries.values()), ): - hook_tags = [tag for tag in kw.tags if tag.startswith(self.prefix)] + hook_tags = [tag for tag in kw.tags if tag.startswith(self.prefix + event_type)] for tag in hook_tags: if tag[len(self.prefix) :] in events: full_name = name + "." + kw.name @@ -75,7 +75,7 @@ def _create_setup_and_teardown( kws: List[str] = [] - for name in self.yield_hooks(events): + for name in self.yield_hooks("before-", events): if kws: kws.append("AND") kws.append(name) @@ -99,7 +99,7 @@ def _create_setup_and_teardown( kws = [] - for name in self.yield_hooks(events): + for name in self.yield_hooks("after-", events): if kws: kws.append("AND") kws.append(name) @@ -120,10 +120,10 @@ def _create_setup_and_teardown( ) def start_suite(self, data: running.TestSuite, result: result.TestSuite) -> None: - self._create_setup_and_teardown(data, ("before-suite", "before-feature")) + self._create_setup_and_teardown(data, ("before-suite", "before-feature", "after-suite", "after-feature")) def start_test(self, data: running.TestCase, result: result.TestCase) -> None: - self._create_setup_and_teardown(data, ("before-test", "before-test")) + self._create_setup_and_teardown(data, ("before-test", "after-test")) # def start_keyword(self, data: running.Keyword, result: result.Keyword) -> None: # # self.call_hooks(("before-keyword", "before-step"))