Skip to content

Automatically assing unique names to pipeline hooks #3541

Description

@vkarak

In the case of mixins and library tests that are meant to be used by other tests, it is a good idea to define the hook names with a unique pattern, e.g., _<ClassName>_<hook_name>, to avoid derived tests accidentally overriding the library or mixin hook which are supposed to provide extra functionality to the test.

Even if a base class wants to override a hook to redefine it or disable it, it would still be able to do it, but in a more explicit way, which I think is good:

class Plugin(RegressionMixin):
    @run_before('run', always_last=True):
    def do_sth(self):
        ...


@simple_test
class DerivedTest(RegressionTest, Plugin):
    def _Plugin_do_sth(self):
        # Short circuit the hook
        pass


@simple_test
class DerivedTest2(RegressionTest, Plugin):
    # Detach base class hook and re-attach it below
    def _Plugin_do_sth(self):
        super()._Plugin_do_sth()

    @run_before('run')
    def do_sth_else(self):
        self._Plugin_do_sth()

See also #3486.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions