Skip to content

Unexpected TRY-EXCEPT behavior in teardown #4293

Closed

Description

@VilleSalonen

Robot Framework version: 5.0

I was migrating from Run Keyword And Ignore Error to TRY-EXCEPT when I encountered the following problem. A developer cannot necessarily know whether their keyword is being run normally or in a teardown but this can dramatically affect how the keyword works.

I can understand the benefit of continuing in teardown to other keywords to make sure that teardown is done as completely as possible but I think that should not occur within a TRY block.

Test code:

*** Test Cases ***
Running TRY Normally
    Keyword With TRY

Running TRY In Teardown
    Log    Test content here.
    [Teardown]    Keyword With TRY

*** Keywords ***
Keyword With TRY
    TRY
        Fail    First failure
        Fail    Second failure
    EXCEPT    First failure
        Log    In EXCEPT
    END

Execution log:

> robot .\try.robot
==============================================================================
Try
==============================================================================
Running TRY Normally                                                  | PASS |
------------------------------------------------------------------------------
Running TRY In Teardown                                               | FAIL |
Teardown failed:
Several failures occurred:

1) First failure

2) Second failure
------------------------------------------------------------------------------
Try                                                                   | FAIL |
2 tests, 1 passed, 1 failed
==============================================================================
Output:  C:\Git\Lifecare-Imaging-Workflows\e2e\output.xml
Log:     C:\Git\Lifecare-Imaging-Workflows\e2e\log.html
Report:  C:\Git\Lifecare-Imaging-Workflows\e2e\report.html

Activity

  1. VilleSalonen commented on Mar 31, 2022

    @VilleSalonen
    Author

    I encountered multiple problems with keywords which are used both normally and in teardown. After thinking this over for a while I'm now hesitant in using TRY-EXCEPT at all and instead relying on older Run Keyword * keywords instead. It seems so dangerous to implement a keyword which works differently based on the context it is being run in.

  2. pekkaklarck commented on Mar 31, 2022

    @pekkaklarck
    Member

    It's true that execution automatically continuing in teardowns makes using TRY/EXCEPT in them complicated. Need to think is there something we could do to that. Notice that you get the same behavior with Run Keyword And Except Error and others as well.

  3. pekkaklarck commented on Apr 7, 2022

    @pekkaklarck
    Member

    The underlying problem here is that in teardowns execution continues also after there are failures. This is done to make sure all cleanup activities are run and cannot be changed. Changing the behavior in TRY block could be considered, but I think it is too magic. We'd also need to decide should the mode change affect possible child keywords. A better solution is making to explicitly turn the continue-on-failure mode off when needed. I submitted #4303 about that and hope it could be implemented already in RF 5.1.

    The current "unexpected TRY-EXCEPT behavior" is considered to be by design and I close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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