From c6b09be3f019a08889f5a388dd6ceb3bd8ab714e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D1=82=D1=8B=D0=BD=D0=BE=D0=B2=20=D0=9C?= =?UTF-8?q?=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=B5=D1=80=D0=B3=D0=B5?= =?UTF-8?q?=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 26 Aug 2024 16:39:08 +0000 Subject: [PATCH] [DOP-18574] Relax check for number of yields in hooks --- docs/changelog/next_release/+yield.feature.rst | 1 + onetl/hooks/hook.py | 2 +- tests/tests_unit/test_hooks/test_hooks_callback.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/next_release/+yield.feature.rst 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):