diff --git a/docs/changelog/next_release/+yield.feature.rst b/docs/changelog/next_release/+yield.feature.rst new file mode 100644 index 000000000..efc586068 --- /dev/null +++ b/docs/changelog/next_release/+yield.feature.rst @@ -0,0 +1 @@ +Do not raise exception if yield-based hook whas something past (and only one) ``yield``. diff --git a/onetl/hooks/hook.py b/onetl/hooks/hook.py index d49297f1b..619cff7d5 100644 --- a/onetl/hooks/hook.py +++ b/onetl/hooks/hook.py @@ -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 diff --git a/tests/tests_unit/test_hooks/test_hooks_callback.py b/tests/tests_unit/test_hooks/test_hooks_callback.py index d1b69cf9e..7fbc00ed7 100644 --- a/tests/tests_unit/test_hooks/test_hooks_callback.py +++ b/tests/tests_unit/test_hooks/test_hooks_callback.py @@ -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):