Skip to content

Commit

Permalink
[DOP-18574] Relax check for number of yields in hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Aug 26, 2024
1 parent 75f74f7 commit c6b09be
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog/next_release/+yield.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not raise exception if yield-based hook whas something past (and only one) ``yield``.
2 changes: 1 addition & 1 deletion onetl/hooks/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def __enter__(self):
try:
self.first_yield_result = self.gen.send(None)
except StopIteration:
raise RuntimeError("generator didn't yield") from None
pass

return self

Expand Down
4 changes: 2 additions & 2 deletions tests/tests_unit/test_hooks/test_hooks_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ def plus(self, arg: int) -> int:
def modify_callback(self, arg: int):
yield from (i for i in ()) # noqa: WPS335

with pytest.raises(RuntimeError, match="generator didn't yield"):
Calculator(1).plus(2)
# no yield = no override
assert Calculator(1).plus(2) == 3


def test_hooks_execute_callback_too_many_yields(caplog):
Expand Down

0 comments on commit c6b09be

Please sign in to comment.