Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/GherkinParser/Library.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ 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
for name, kw in chain(
*([(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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"))
Expand Down