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

Context.execute_steps: if failed both steps are returned as failed steps, this results in problems #992

Open
berndhahnebach opened this issue Jan 10, 2022 · 2 comments
Labels

Comments

@berndhahnebach
Copy link

berndhahnebach commented Jan 10, 2022

related to #983

I do execute some code if a step fails. For this in environment.py in def after_step(context, step): I just check if step.status == "failed":

If Context.execute_steps is used the code is executed twice because both steps are returned as failed steps. The origin step and the step which was called by the origin step. Is it possible to somehow only get the origin step status and to omit the step which was called.

Eventually the aim is to execute the code only once and not twice.

@jenisys
Copy link
Member

jenisys commented Jan 11, 2022

The theoretical case is even worse. Instead of 2 levels (caller and callee), you can have multiple nested levels of ctx.execute_steps() instead of only one.

Currently, I am not aware of an easy mechanism to detect on which side you are are.
I need to look into that.

UNTIL THEN:

  • You can inspect the stack-frame and make decisions based on that (low-level)
  • You can add an attribute(s) to the Context object that helps you if the step was already handled (or what error handling strategy you use). You will need to add this attribute (if not already present) before you call ctx.execute_steps() or use a Python ContextManager (enter/exit) to help you.

NOTES:
The outer failing step that calls ctx.execute_steps() is the primary interesting failing step for the user/test-runner. The inner failing steps is for diagnostics to understand why the outer step failed.

@berndhahnebach
Copy link
Author

berndhahnebach commented Jan 13, 2022

Thanks for your hints. What I did the time being. May be some hack, but it works so far ...

before_scenariao I create a step_counter = 0 , before_step I add 1 and after step I reduce by 1. I am only interested in the steps which have step_counter ==1 On after_scenario the step_counter should be == 0 again.
Since I do not really need the diagnostics this works quite well so far. I only need the objects where the step fails. Since in the failing step I do write them in the context I have them available.

I may have a look at your ideas as well.

cheers bernd

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

No branches or pull requests

2 participants