diff --git a/reframe/core/hooks.py b/reframe/core/hooks.py index e7475b5b1d..2ad0b99e21 100644 --- a/reframe/core/hooks.py +++ b/reframe/core/hooks.py @@ -151,7 +151,10 @@ def add(self, v): ''' if hasattr(v, '_rfm_attach'): - self.__hooks.add(Hook(v)) + # Always override hooks with the same name + h = Hook(v) + self.__hooks.discard(h) + self.__hooks.add(h) elif hasattr(v, '_rfm_resolve_deps'): v._rfm_attach = ['post_setup'] self.__hooks.add(Hook(v)) diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index 67c78775bc..a62570c0d1 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -831,6 +831,21 @@ def y(self): assert test.foo == 10 +def test_overriden_hook_different_stages(HelloTest, local_exec_ctx): + @test_util.custom_prefix('unittests/resources/checks') + class MyTest(HelloTest): + @run_after('init') + def foo(self): + pass + + @run_after('setup') + def foo(self): + pass + + test = MyTest() + assert test.pipeline_hooks() == {'post_setup': [MyTest.foo]} + + def test_disabled_hooks(HelloTest, local_exec_ctx): @test_util.custom_prefix('unittests/resources/checks') class BaseTest(HelloTest):