Skip to content

Scope of Before/After Hooks in GoDog ScenarioContext Affecting All Scenarios #683

Open
@aakash-acquia

Description

@aakash-acquia

👓 What did you see?

In my test setup, I have a main FeatureContext that registers scenarios and a nested AbcFeatureContext that also registers its own scenarios and hooks.

func FeatureContext(ctx context.Context, s *godog.ScenarioContext, log logger.Logger) {
   // Main steps and hooks
   AbcFeatureContext(ctx, s)
}

func AbcFeatureContext(ctx context.Context, s *godog.ScenarioContext) {
    s.Before(func(ctx context.Context, _ *godog.Scenario) (context.Context, error) {
        // Pre-checks specific to AbcFeatureContext
        return ctx, nil
    })

    // Steps specific to AbcFeatureContext

    s.After(func(ctx context.Context, _ *godog.Scenario, _ error) (context.Context, error) {
        // Cleanup specific to AbcFeatureContext
        return ctx, nil
    })
}

I have noticed that the Before and After hooks defined in AbcFeatureContext are being executed for all scenarios registered in FeatureContext, not just for those specific to AbcFeatureContext.

✅ What did you expect to see?

I expected the hooks in AbcFeatureContext to apply only to scenarios that are meant to be part of AbcFeatureContext and not to every scenario registered under FeatureContext.

📦 Which tool/library version are you using?

go 1.23.0
godog v0.14.1

🔬 How could we reproduce it?

No response

📚 Any additional context?

Also let me know if this is expected behaviour and you have any workaround for it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions