Skip to content

Libraries should get notification when suites/tests/keywords start/end and when library is out of scope #811

Closed

Description

@spooning

Originally submitted to Google Code by @pekkaklarck on 1 Apr 2011

Basically this would allow libraries to act as listeners. The most important use case is libraries with global or suite level scope to be able to handle test specific state easily, but I'm sure there are other usages too. Even more use case are possible if listeners are allowed to alter suite/test/keyword state (issue 177).

To make it easier to distinguish listener methods from keywords be probably should not use normal listener method names like start_test but add a prefix like listen_to_start_test. Regardless the name, this change is potentially backwards-incompatible because old keywords with these names won't work anymore. One possibility to prevent that is requiring libraries that act as listeners to have ROBOT_LISTENER_VERSION attribute.

An additional problem is handling dynamic libraries. One possibility is expecting also these libs to have listener methods directly in the class, but this approach does not support proxys such as Remote. Allowing listener names to be returned from get_keyword_names and executed via run_keyword would be better but harder to implement. Notice also that requiring special attributes is something that does not work with proxy libraries either.

Activity

  1. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @mkorpela on 1 Apr 2011

    Another idea:
    Libraries and resource files could have setup and teardown functions / keywords.

    This would allow cross suite setup and teardown reuse. For example a resource file could be used to completely setup and teardown the system under test or a connection or open/close some file etc..

  2. added this to the 2.8.5 milestone on Jun 29, 2014
  3. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @yanne on 3 May 2011

    Initially descoped from 2.6 and moved to 2.7.

  4. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 8 Jun 2011

    Issue 857 has been merged into this issue.

  5. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @spooning on 2 Dec 2011

    Initially descoped from 2.7 due to lack of time

  6. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 26 May 2014

    As this is needed inside NSN, we are adding this to 2.8.5.

    We ended up deciding that this would work by library having an attribute ROBOT_LIBRARY_LISTENER which has the listener instance as value. This can be self. To avoid having the listener methods visible as keywords, the method names can also start with underscore.

    Changing the test status etc will not be supported for now and neither are Remote libraries.

    This way the changes should be also backwards compatible.

  7. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 26 May 2014

    This issue was updated by revision a67147545207.

    First implementation still lacking tests and support for methods starting with underscore.

  8. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 27 May 2014

    This issue was updated by revision ba322e157438.

    Added missing librarylisteners.py and also some tests

  9. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 27 May 2014

    This issue was updated by revision f1c15e0bfa69.

    Added support for methods names starting with underscore

  10. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 28 May 2014

    This issue was updated by revision dcbc2df1b16c.

    If a library works as a listener, it is created at the beginning of the scope. (Test scope listener will get start test event, suite scope will get the start suite etc)

  11. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 28 May 2014

    This issue was updated by revision f2fcbe6f0011.

    Now works with java

  12. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 28 May 2014

    This issue was updated by revision e91d3dfdd21a.

    support starting with underscore in Java

  13. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 28 May 2014

    This issue was updated by revision b4e92a185fb7.

    Add tests for suite setup and teardown events in test scope

  14. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 28 May 2014

    This issue was updated by revision 51f5609306a5.

    Cleanup and more tests

  15. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 28 May 2014

    This issue was updated by revision d0aa87b9c5af.

    Cleanup

  16. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by bryan.oakley on 4 Jun 2014

    This looks very useful. It makes it trivial to implement the "Require test case" keyword that I requested in issue #1710 .

  17. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 9 Jun 2014

    This issue was updated by revision 970e12328222.

    Now calling close method from library listener when ending the scope for that library.

  18. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 10 Jun 2014

    This issue was updated by revision 444ad697ff45.

    Documented the new functionality in User Guide. Jussi, and everyone
    else interested, please review and let me know if something is missing
    or is not clear.

  19. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 10 Jun 2014

    @⁠bryan.oakley Yeah, this functionality provides lot of interesting capabilities. I'm pretty happy about the design too. It's really easy to make a library act as a lis

  20. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @jussimalinen on 11 Jun 2014

    r2c8f8b6cea69 contains a fix to allow module libraries to have a listener.

    I didnt make a separate test for all features though. The module test has a listener with api version v1, and the listener is external (not the module itself, which you could access with a hackish way of sys.modules[name])

    The empty library also got now log_message implemented to verify that also.

    r62c8ed20ad22 has test to verify that libraries taken into use with import library also work.

    I think this feature should be done.

  21. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @Tattoo on 11 Jun 2014

    User Guide reviewed, looks okay

  22. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 12 Jun 2014

    Latest code changes look good too. Closing and looking forward to see this functionality to be used in real life!

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions