Skip to content

Allow giving listener and model modifier instances to robot.run and TestSuite.run #1969

Closed

Description

@uSpike

As briefly discussed on IRC, I have a need to register an instance of a listener object at run-time, programmatically. I am wrapping Robot in another application, running urwid. Robot is running in a thread, and I want to update a widget based on Robot's current status. A listener would be the obvious choice for an interface between the applications.

Currently, most classes related to Listeners and logger proxies assume that the wrapped object is a string and must be imported. I have overridden some of the core classes to allow instances to be passed in.

Activity

  1. pekkaklarck commented on Apr 13, 2015

    @pekkaklarck
    Member

    Would it be enough that in addition of

    from robot import run
    run('tests.robot', listener='listener.py')

    you could also do

    from robot import run
    run('tests.robot', listener=Listener())

    I know I would have liked the above functionality few times. It shouldn't be too complicated to implement either.

  2. vkruoso commented on Apr 13, 2015

    @vkruoso
    Contributor

    I'm also interested on a feature like this, but my use case is a little bit different. I've sent an email in the users list: "Add listener instance using robot.api".

    The idea is to be able to register a listener instance at any point in robot execution. In my use case it would be in the initialization method of robot's dynamic library (that library works as a proxy).

  3. pekkaklarck commented on Apr 13, 2015

    @pekkaklarck
    Member

    @vkruoso, libraries can register listeners since RF 2.8.5 (#811). Does that work for you?

  4. vkruoso commented on Apr 13, 2015

    @vkruoso
    Contributor

    @pekkaklarck, I'm already using that interface. Let me be a little more clear.

    class Proxy(object):
        ROBOT_LISTENER_API_VERSION = 2
        def __init__(self):
            self.ROBOT_LIBRARY_LISTENER = self

    So the Proxy library act as a listener. Great. Now, in the init method (could be in any other), I create a bunch of instances. So what I have is something like:

    (instances, keywords) = Loader().load_libraries()

    Now my wish was to register each instance as a listener calling a robot API function (and was also hopping it would check for the ROBOT* attributes). It could be a BuiltIn() method/keyword? register_listener for instance.

    It might be interesting to restrict scope for those instances so it receives only events from the suite they have been registered.

  5. pekkaklarck commented on Apr 13, 2015

    @pekkaklarck
    Member

    I see. Would it be enough is ROBOT_LIBRARY_LISTENER could be a list of listeners? That ought to be pretty easy to implement, but would require listeners to be created in __init__. An API to register listeners at any time would be more flexible and could be used also other code than libraries, but it would need a way to restrict the scope of the listener or/and have a way to unregister a listener. This would also be a new API and thus a bit more work to implement, test and document.

    @spikergit1, are you also looking for an API to register listeners at any time or would being able to pass a listener instance to robot.run and TestSuite.run be enough in your use case?

  6. uSpike commented on Apr 13, 2015

    @uSpike
    Author

    @pekkaklarck being able to pass instances to robot.run and/or TestSuite.run would be enough for me, for now. I do see a benefit in "an API to register listeners at any time", and honestly having combed through the Listener code I don't think it'd be too hard to do. I could submit a PR if you're interested.

  7. pekkaklarck commented on Apr 13, 2015

    @pekkaklarck
    Member

    Personally I have had more needs for passing listener objects to robot.run than for having an API to register them at run time. I don't see a problem having both of these possibilities, though, and ROBOT_LIBRARY_LISTENER could be enhanced to accept a list of listeners as the third option. I consider these separate enhancements that require their own issues and possible PRs, though.

    Should we agree that this issue is about passing objects to robot.run and TestSuite.run, and a new issues are submitted about possible other enhancements? If you agree, please submit issues about enhancements you care about. Please also provide PRs for issues you really care about.

  8. vkruoso commented on Apr 14, 2015

    @vkruoso
    Contributor

    I will open a separate issue to support lists on ROBOT_LIBRARY_LISTENER and will try to provide a pull request for it.

  9. added this to the 2.9 milestone on Apr 23, 2015
  10. pekkaklarck commented on Apr 23, 2015

    @pekkaklarck
    Member

    Thanks @vkruoso for submitting #1970 about enhancing ROBOT_LIBRARY_LISTENER to support lists. This issue is now officially about being able to pass actual listener instances to robot.run and TestSuite.run.

    We are planning to add support for visitors that can modify test suites before execution in RF 2.9 (#1976). We plan to support something like --visitor MyVisitor from the command line, similarly as with listeners, but also want to be able to pass actual visitor instances to robot.run and TestSuite.run. Same helper probably can handle both listeners and visitors so it makes sense to include also this issue in RF 2.9.

  11. changed the title [-]Support listener instance registration[/-] [+]Allow giving listener instances to `robot.run` and `TestSuite.run`[/+] on Apr 23, 2015
  12. WojtekKowaluk commented on May 6, 2015

    @WojtekKowaluk
    Contributor

    hey, we are working on this task. we will make pull request tomorrow after code review.

  13. 6 remaining items

  14. pekkaklarck commented on Jun 2, 2015

    @pekkaklarck
    Member

    Now that #1993 that @WojtekKowaluk encountered when implementing this feature is fixed, it's possible to look at this issue again. We already dropped this from alpha 2 because we plan to create it tomorrow, but if we get a good PR adding this back is still possible.

    Notice that the PR doesn't need to contain fixes to listeners, variable files and modifiers, just concentrating on listeners is enough. Separate PRs and possible separate issues can then be submitted about others.

  15. WojtekKowaluk commented on Jun 3, 2015

    @WojtekKowaluk
    Contributor

    I have rebased PR on master branch. I think I will leave variable files and modifiers for other PR. I'm waiting for your comments.

  16. added a commit that references this issue on Jun 10, 2015
  17. pekkaklarck commented on Jun 10, 2015

    @pekkaklarck
    Member

    PR #1987 implementing the listener part of this issue was merged in 7dd3a9b and @WojtekKowaluk promised also to continue with variable files and modifiers.

  18. pekkaklarck commented on Jun 15, 2015

    @pekkaklarck
    Member

    Have you @WojtekKowaluk already looked at variable files and modifiers? If not, I can easily take care about them today or tomorrow. We try to get alpha 3 ready this week and would like to get this one finished before that.

  19. WojtekKowaluk commented on Jun 15, 2015

    @WojtekKowaluk
    Contributor

    hello, please go ahead. I don't feel like I am able to complete this in timely manner. I think I will help Stan with detecting unused imports instead or do other task with low priority.

  20. pekkaklarck commented on Jun 15, 2015

    @pekkaklarck
    Member

    Modifiers done. Variable files turned out to be a bit more complicated. Need to think can they handled cleanly without too much work.

  21. changed the title [-]Allow giving listener, variable file and model modifier instances to `robot.run` and `TestSuite.run`[/-] [+]Allow giving listener and model modifier instances to `robot.run` and `TestSuite.run`[/+] on Jun 16, 2015
  22. self-assigned this
    on Jun 16, 2015
  23. pekkaklarck commented on Jun 16, 2015

    @pekkaklarck
    Member

    I decided to drop variable files from the scope of this issue for the following reasons:

    • Supporting them would have required more changes to variable file import logic. Nothing major but not exactly trivial either.
    • Nobody has actually asked that functionality.
    • It would probably be a better idea to allow passing variables as a dict like {'var1': 'value', 'var2': 2} anyway.

    A new issue can be submitted if someone wants to make it easier to pass variables to the programmatic APIs. We can then separately decide what is the best way to implement it.

    This issue now covers only listeners and model modifiers which are both done.

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