Skip to content
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

ScenarioContext.AfterStep not invoked after a failed case #370

Closed
stroem opened this issue Jan 26, 2021 · 5 comments · Fixed by #409
Closed

ScenarioContext.AfterStep not invoked after a failed case #370

stroem opened this issue Jan 26, 2021 · 5 comments · Fixed by #409
Labels
🐛 bug Defect / Bug
Milestone

Comments

@stroem
Copy link

stroem commented Jan 26, 2021

What version of godog are you using?

Godog version is: v0.11.0

What version of Go are you using?

go version go1.15.1 darwin/amd64

What did you do?

I enabled the hooks BeforeStep and AfterStep on godog.ScenarioContext to output som logs after each step, and it worked just fine, until one step failed. After the step failed the BeforeStep was invoked but not the AfterStep.

What did you expect to see?

Either both the AfterStep and BeforeStep is invoked on following steps after a failed step or both AfterStep and BeforeStep is not invoked after a failed step.

What did you see instead?

BeforeStep was invoked for every step after a failed step, but not the AfterStep.

@stroem stroem added the 🐛 bug Defect / Bug label Jan 26, 2021
@lonnblad
Copy link
Member

lonnblad commented Jan 27, 2021

@stroem, thanks for the issue!

How would you prefer this, always execute the hooks, even on skipped steps or not execute them?
If we would execute the hooks, would you like to have some form indication that this step won't be executed?

BR Fredrik

@fgm
Copy link

fgm commented Jan 29, 2021

I think it is safer to have them execute always, using the test status if desired to act differently depending on success, failure or being skipped.

@lonnblad
Copy link
Member

@fgm, Thanks for your feedback!
How do you see this status being propagated to the hook or is it up to the user to keep this information from the last AfterStep-hook?

@fgm
Copy link

fgm commented Jan 30, 2021

Haven't look in detail, but I think the info is already present on the PickleStep passed to the hook, is it not ?

@lonnblad
Copy link
Member

lonnblad commented Mar 5, 2021

@fgm I don't think so, we only pass the parsed Step information as of now.

I propose doing like this, change so that we execute the AfterStep as well and keep the BeforeStep as is, so we make it consistent and then have another discussion on how we can indicate that a specific step won't be executed or if we should skip the hooks completely.

The discussion (#360) about adding context to the step execution might also be a good topic to take up this issue in a future solution.

@lonnblad lonnblad added this to the v0.12.0 milestone Mar 5, 2021
vearutop added a commit that referenced this issue Aug 3, 2021
* Add new contextualized API for hooks and steps

* Make default context configurable

* Run AfterStep hooks even after failed steps, fixes #370

* Update CHANGELOG and README

* Add step result status to After hook, fixes #378

* Elaborate hooks documentation

* Add test to pass state between contextualized steps

* Update README with example of passing state between steps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants