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: Support @runner.continue_after_failed_step (hint: does not work when multiple steps are called) #953

Open
sbedi123 opened this issue Aug 21, 2021 · 9 comments
Labels

Comments

@sbedi123
Copy link

sbedi123 commented Aug 21, 2021

The tag @runner.continue_after_failed_step does not work when multiple step are called inside context.execute_steps

I have a simple feature file with which has a scenario with tag @runner.continue_after_failed_step
The second step in the feature file uses context.execute_steps to call two steps.
When the first step fails the test does not continue to next step.

How can i make it execute all the steps in context.execute_step even if some step fails?

@sbedi123
Copy link
Author

sbedi123 commented Aug 21, 2021

Feature file:

Feature: Opt-In (HasOffers)

  @runner.continue_after_failed_step
  Scenario Outline: Opt-in end2end test starting with a HasOffers link
    Given that I follow a HasOffers link to the "<page_name>" landing page
    Then I verify pixel tracking events test
    

steps in py file

@step('I verify pixel tracking events test')
def verify_pixel_events(context):
        context.execute_steps('''
            then I want to test1
            and I want to test2
        ''')


@step('I want to test1')
def test1(context):
    assert False


@step('I want to test2')
def test1(context):
    print('Hello')

@sbedi123
Copy link
Author

So my issue is after the step 'I want to test1' fails it does not execute step 'I want to test2'. How can i make it work?

@sbedi123 sbedi123 changed the title The tag @runner.continue_after_failed_step does not work when multiple step are called inside context.execute_steps The tag @runner.continue_after_failed_step does not work when multiple steps are called inside context.execute_steps Aug 21, 2021
@jenisys
Copy link
Member

jenisys commented Aug 21, 2021

@runner.continue_after_failed_step is a hack. Therefore, ctx.execute_steps() was probably never considered for this functionality.

In general, it is a bad idea to continue executing steps after the first one has failed.

  • You will only get correlated failures because the preconditions of the following steps are not met
  • You waste time (instead of bailing out of the failed test)

@sbedi123
Copy link
Author

sbedi123 commented Aug 21, 2021

The reason I am using here the multiple steps I am calling are independent of each other. So its fine if one fails and other passes I just want it to go thru all the steps. Will I need to use try catch and ask it to execute even if exception occurs?

@jenisys
Copy link
Member

jenisys commented Aug 21, 2021

What is the failure: An assert failed (AssertionError exception) or another exception ?
If it is an exception (unexpected failure), it would catch-and-ignore it.
This will allow you to move on.

NOTES:
These exception(s) must be addressed later-on.

@sbedi123
Copy link
Author

sbedi123 commented Aug 21, 2021 via email

@jenisys
Copy link
Member

jenisys commented Aug 21, 2021

Then:

  • Temporarily disabled the assert statement(s) or catch-and-ignore the exception
  • Patch behave.runner:Context.execute_steps() to continue after a failed step

@jenisys jenisys changed the title The tag @runner.continue_after_failed_step does not work when multiple steps are called inside context.execute_steps context.execute_steps: Support @runner.continue_after_failed_step (hint: does not work when multiple steps are called) Aug 21, 2021
@sbedi123
Copy link
Author

sbedi123 commented Aug 21, 2021 via email

@jenisys
Copy link
Member

jenisys commented Aug 21, 2021

HINT FOR: Patch of Context.execute_steps()

  • Prevent assert False, message in the step has not passed case
# — IN FUNCTION: Context.execute_steps()If not passed:
    …
    # ORIGINAL-LINE: assert False, message. #< LINE OF INTEREST
    assert self.scenario.continue_after_failed_step, message

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