Skip to content

Support keywords and control structures with listener version 3 #3296

Closed

Description

@bergstenarn

I would like to see support for start_keyword and end_keyword in listener version 3.

Activity

  1. added this to the v4.0 milestone on Feb 15, 2020
  2. pekkaklarck commented on Feb 15, 2020

    @pekkaklarck
    Member

    The problem implementing this is that on the execution side there currently isn't any place where we could call start/end_keywords so that they would get data and result objects similarly as other listener v3 methods get. Changing that would require quite big changes to the code and doing them just to get this feature implemented hasn't been considered worth the effort.

    In RF 4.0 the plan is to add new features like IF/ELSE (#3074) that require big changes to the execution side. When doing them, this issue definitely needs to be taken into account. Thus assigned this one to the v4.0 scope.

  3. changed the title [-]Support for start/end_keyword in listener version 3[/-] [+]Support for `start/end_keyword` in listener version 3[/+] on Feb 15, 2020
  4. Snooz82 commented on Apr 29, 2020

    @Snooz82
    Member

    i really like this feature.
    including line numbers for start and end keyword!
    This would be a huge enabler for debuggers!

  5. modified the milestones: v4.0, v3.3 on May 27, 2020
  6. dakaizou commented on Aug 11, 2020

    @dakaizou

    Hi @bergstenarn and @Snooz82 ,
    I'm not sure what those problems mentioned by @pekkaklarck are. Maybe there are some potential issues, but I patched the keyword runners to get something similar, and it worked fine for me:

    from functools import wraps
    
    import robot
    from robot.running.librarykeywordrunner import LibraryKeywordRunner
    from robot.running.userkeywordrunner import UserKeywordRunner
    
    ROBOT_LISTENER_API_VERSION = 3
    
    
    def start_keyword(kw, context):
        print(kw.lineno)
        print(kw.source)
    
    
    def end_keyword(kw, context):
        print(kw)
    
    
    def patch_kwrunner(runner):
        old_run = runner.run
    
        @wraps(old_run)
        def wrapper(self, kw, context):
            start_keyword(kw, context)
            try:
                if False:
                    # bypassing this keyword
                    return self.dry_run(kw, context)
                return old_run(self, kw, context)
            finally:
                end_keyword(kw, context)
    
        runner.run = wrapper
    
    
    def start_suite(suite, result):
        patch_kwrunner(LibraryKeywordRunner)
        patch_kwrunner(UserKeywordRunner)
    
    
    if __name__ == "__main__":
        robot.run("main_suite.robot", listener=__file__)
    
  7. self-assigned this
    on Sep 15, 2020
  8. mkorpela commented on Sep 16, 2020

    @mkorpela
    Member

    Related draft pull request #3672

  9. removed their assignment
    on Sep 16, 2020
  10. damies13 commented on Nov 11, 2020

    @damies13

    Hi,

    rfswarm agent uses the following version 2 api methods:

    • start_suite
    • log_message
    • end_keyword

    So not having "end_keyword" in the version 3 listener API is preventing me upgrading rfswarm from the version 2 API, fortunately the version 2 API works in Robot Framework V3 and hopefully won't be depreciated be in Robot Framework V4?

    damies13/rfswarm#67

    For my project I would be happy to skip V3 and jump to V4 if end_keyword never gets implemented in V3 but does get implemented in V4 api methods.

  11. 32 remaining items

  12. pekkaklarck commented on Dec 14, 2023

    @pekkaklarck
    Member

    Tests have been added. There are only two tests in the body_items_v3.robot file under atest/robot, but they are pretty thorough. The first test validates that all listener methods are called and the latter validates modifying data. You can see tests. listeners and a library these tests use in the body_items_v3 directory under atest/testdata. If you are interested in all interesting (and to some extend crazy) ways the data can be manipulated, see the the DataModifier listener.

    I wrote earlier that it might be a good idea to add error codes or some other mechanism for differentiating various error situations to ease handling them. I still believe it could be useful, but I'm not sure how important it would be or how it should actually work. I believe this is something that's best left for the future.

    This feature ought to now be ready except for documentation. That mainly means User Guide, but probably API docs can be enhanced as well. That's something we can do after beta 1 or even after we have a release candidate out.

  13. pekkaklarck commented on Dec 15, 2023

    @pekkaklarck
    Member

    There were still problems related to modifying results. Because information was already written to output.xml, modifications didn't have any real effect. That was fixed by the above commit, and more tests for modifying results will be committed shortly. Tests are modified quite a bit also otherwise (for example, there will be multiple tests under atest/robot), but they use the same files that were mentioned in the comment above. Hopefully this feature is now ready except for documentation.

  14. changed the title [-]Support for `start/end_keyword` in listener version 3[/-] [+]Support keywords and control structures with listener version 3[/+] on Dec 15, 2023
  15. added a commit that references this issue on Jan 26, 2024
    a5dac71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions