question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange behaviour when redefining hook and assigning it to a different stage

See original GitHub issue

The following code leads to the strange behaviour that the second check_x() overrides the first (as expected) but the hooks are not overridden, leaving the second check_x() executing as a post-init hook. We should either disable redefinitions of the same hook in the same class or have the second definition and hook override completely the first one.

@simple_test
class my_test(RegressionTest):
    x = variable(int, value=10)

    @run_after('init')
    def check_x(self):
        '''Test will not be listed or run if filtered here'''
        self.skip_if(self.x < 3, 'x is lower than 3')

    @run_after('setup')
    def check_x(self):
        '''Test will be skipped during runtime'''
        self.skip_if(self.x < 5, 'x is lower than 5')

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
teojgocommented, Feb 17, 2022

What actually happens is the following:

  1. check_x is first added to the hook registry as a post_init hook https://github.com/eth-cscs/reframe/blob/12b48588980e411fbfe17f32b864fd6eaf7450b5/reframe/core/hooks.py#L154
  2. check_x is added to the hook registry as a post_setup hook, but because it’s wrapped as a Hook instance and has the same name as the check_x on step 1, it’s not taken into account, since a hook with the same name is already in the registry
  3. Finally when the hooks are assigned to each stage of the pipeline via https://github.com/eth-cscs/reframe/blob/12b48588980e411fbfe17f32b864fd6eaf7450b5/reframe/core/hooks.py#L82, the hook that resides in the registry is the post_init one with the check_x name, but the RegressionTest object attribute named check_x refers to the second check_x function that replaced the first.
  4. Therefore, you have the second check_x executed as a post_init hook

I suggest overriding completely a hook with the same name if redefined as another stage hook.

0reactions
vkarakcommented, Feb 17, 2022

Nice find and intricate bug! Thanks @teojgo for investigating!

I suggest overriding completely a hook with the same name if redefined as another stage hook.

Yes, I think it makes sense and it is compatible with what happens when a hook is redefined in a subclass.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TIP 57 Trauma-Informed Care in Behavioral Health Services
Strategy #4: Assign a Key Staff Member To Facilitate Change . ... ment principles that guide clinicians, other behavioral health workers, and administrators ......
Read more >
Lorber. “Night to his Day”: The Social Construction of Gender
In the construction of ascribed social statuses, physiological differences such as sex, stage of development, color of skin, and size are crude markers....
Read more >
Teaching To Transgress - University Blog Service
really belonging, taught me the difference between education as the practice of freedom and education that merely strives to reinforce domination. The rare...
Read more >
The Secrets to Successful Strategy Execution
The new chief executive chose to focus less on cost control and more on profitable growth by redefining the divisions to focus on...
Read more >
The Norton Sampler 9e - Parma City School District
W. W. Norton & Company, Inc., 500 Fifth Avenue, New York, NY 10110 ... though you were a reporter on assignment or a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found