Skip to content

feat: Add ClearInitializers and ClearFinalizers method #2275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Kirdock
Copy link

@Kirdock Kirdock commented May 23, 2025

These methods let you clear any set initializer and finalizer.

Why this change?

You may want to start tests cleanly. TestA could add finalizers, and another one, TestB, could also add some, but then TestB also has and executes TestA's finalizers.

These methods let you clear any set initializer and finalizer.
@CLAassistant
Copy link

CLAassistant commented May 23, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure how initializers and finalizers are used.

I'm surprised they are global, and the fact we could face race issues.

I would have expected these methods signatures to use *testing.T as argument, so a t.Cleanup could have been used with OnFinalize and OnFinalize, but I'm unsure if these methods are only related to existing tests.

So here, I'm unsure I would have coded the initializer and finalizers like this.

But these considerations are with pre-existing code, the signatures are public, they cannot be changed.

Let's go back to your PR now, it provides a solution for a problem, so I would say why not.

@marckhouzam might provide a better feedback than mine, but for now, and based on my understanding I approve this PR

@Kirdock
Copy link
Author

Kirdock commented May 23, 2025

@ccoVeille had the same thought, so does anything speak against having a Finalize function on a command that is deferred right after this line or after retrieving the flags?

@Kirdock
Copy link
Author

Kirdock commented May 23, 2025

Follow-up: #2276

@ccoVeille
Copy link
Contributor

@ccoVeille had the same thought, so does anything speak against having a Finalize function on a command that is deferred right after this line or after retrieving the flags?

Nothing I know, maybe @marckhouzam will have some thoughts about it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants