Hi, I try to write some tests for kedro pipeline a...
# questions
a
Hi, I try to write some tests for kedro pipeline and include some hooks in it. I started from example:https://docs.kedro.org/en/stable/development/automated_testing.html#create-an-example-test There
_create_custom_hook_manager()
is called, upon which I call
.register(MyHook())
, and then try to run some pipeline with:
SequentialRunner(is_async=True).run(model_pipeline, catalog, hook_manager)
However it does not work, the hook does not get called. Any ideas what am I missing?
1
Untitled.py
CustHook has some hooks defined, like
after_node_run
where I
assert False
to notice it being executed, but it's skipped
n
Can you show
CustHook
?
a
Yea I was debugging and got to the answer: I forgot to add @hook_impl decorators after I inherited from other class when overriding hook methods
Thanks to this journey I got to see in detail how pluggy hook registering mechanisms work xD
👍🏼 1
n
yeah I was suspecting it's
hook_impl
Let us know if you spot anything! the test documentation is relatively new
a
I'm ashamed of asking question about it 😞
n
nah no worries, I make the same mistakes 100 times
everytime I create a hook I do a print to make sure it is actually running
There are hook validation for invalid @hook_impl, maybe it could also validate if there is no hook method registered
keep asking!
d
@Nok Lam Chan do you think it’s possible for us to catch that sort error for the user?
n
https://github.com/kedro-org/kedro/issues/2862 The original implementation does not cover this but I think it should be feasible.
❤️ 1
d
feels like a really good thing to fix so people don’t need to read pluggy internals to extend kedro 🤔
👍 1
cc @Juan Luis
a
I saw that you can override function that detects whether function is a hook or not, we could provide a version that does not need @hook_impl or gives you a warning if the function is called like a registered hook but misses @hook_impl
also bonus question in my testing with hooks topic: so after/before node created hooks get called fine with sequential runner, but hooks like
after_context_created
does not get called by class
KedroContext
and I don't know what actually calls
after_pipeline_run
hook - in my test I had to call those 2 manually to make the hook behave - is there a better way to use some kedro internal objects that do the hook calling for me?
n
Session.load_context() is my bet, do you mind open a new thread or issue for this question? I think this is a good question and deserves some attention