You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New listener API that gets real suite/test objects as arguments and can modify them #1208
Originally submitted to Google Code by bryan.oakley on 27 Aug 2012
I would like to see a listener mode that passes the actual objects to the listeners rather than just a few attributes. For example, I would like to be able to write a listener like this:
Implementation is pretty straight-forward. In robot/output/listeners.py a new clause would be added for each method. For example:
def start_suite(self, suite):
for li in self._listeners:
if li.version == 1:
li.call_method(li.start_suite, suite.name, suite.doc)
elif li.version == 2:
attrs = self._get_start_attrs(suite, 'metadata')
attrs.update({'tests' : [t.name for t in suite.tests],
'suites': [s.name for s in suite.suites],
'totaltests': suite.get_test_count()})
li.call_method(li.start_suite, suite.name, attrs)
elif li.version == 3:
li.call_method(li.start_suite, suite)
This takes a big step forward toward being able to control a test run via the listener interface. The next step would be to put methods on the objects that control the state of the test run. For example, a start_suite listener might do something like 'suite.fail("blah blah")' to cause the suite to fail at the point the listener was called.
The modification of the objects is not the subject of this feature request; that will come in a later feature request. This request is solely for the ability for the listener interface to pass the objects to the listeners.
UPDATE: Jump to this comment to skip old discussion and to see how this new API is actually going to be implemented.
Originally submitted to Google Code by bryan.oakley on 14 Sep 2012
After implementing this on my machine, I think we can do better. Instead of passing in a suite, testcase, or keyword depending on the method, why not have a single "test run" object that contains all of that information? For example:
def start_keyword(self, testrun):
print " current suite:", testrun.suite
print " current test:", testrun.testcase
print "current keyword:", testrun.keyword
Of course, these values could be None depending on the context. For example, testrun.testcase and testrun.keyword would be None when start_suite and end_suite are called.
I like this better because it's easy to document (and thus easier to learn and use), and because it's more extensible. We can evolve the Testrun class over time to include other information that might be useful to the listener interface (eg: namespace, current statistics, etc). This makes it really easy to pass more information to the listener without having to add yet another listener api.
Another advantage is that if the test runner ever changed to support debugging features such as skipping or rerunning tests or keywords, etc, that functionality can be implemented via this object without having to add yet another listener interface. For example, maybe a listener could cause the current suite to abort with "testrun.abort('killed by the listener')". Obviously this means that the Testrun class is tightly coupled to the test runner, but better than that trying to put that coupling deeper, at the suite, test and keyword object layer.
Originally submitted to Google Code by bryan.oakley on 26 Sep 2012
I've implemented this in a clone of robotframework. Any chance this could get merged into 2.7.5?
The documentation is a little weak but it's enough to get started. I would be happy to clean it up, and fix any issues with it or the code before it is released. I've implemented a simple acceptance test for it as well.
I've updated the code to use proxy objects in the TestRun object, rather than the actual objexts. This way we can control exactly what gets pushed to the listener. The changelog where I added the proxies is here:
One rather big problem with the proposed listener API is that the objects to be passed are going to change heavily in RF 2.8 ( issue 825 ). It's unclear how the new objects will look like and I don't want to make any backwards compatibility promises related to them. This doesn't mean the API couldn't be added, but the documentation should clearly state that the objects passed in are going to change.
Originally submitted to Google Code by bryan.oakley on 11 Oct 2012
With or without proxies, I think it's perfectly acceptable to say this interface could change when 2.8 comes out, as long as you don't remove any of the functionality that's already there.... I like the proxies because it gives you more freedom in what you do for 2.8, knowing that the listeners will receive a streamlined proxy object that has none of the internal attributes and methods necessary for the test to run.
My original implementation didn't use proxies, and that certainly gives more power to the listener. I'm never against having more power! Plus, if you add some cool new feature to the actual object you don't have to remember to update the proxy to provide the same feature to the listener. I think it comes down to whether you want a lean interface that can withstand a lot of changes to the internal objects, or a rich interface that may break (or at least change) from release to release.
I really appreciate you considering putting this in 2.7.5. If there's anything else I can do to help make that happen, let me know.
They need to be updated in 2.8. If we pass the real objects, this listener API itself doesn't need to change at all. Passed objects change obviously change, but if this possibility is documented clearly users can take it into account. You could, for example, create needed proxies on your own listeners.
As you pointed out, proxies take some of the power away from the API. You would be limited to the functionality provided by them. This would probably also lead to further enhancements to add more functionality to them in the future.
If we agree that using real objects is the way to go, getting this enhancement into 2.7.5 ought to be possible. The best way to help with that is creating a patch with the required changes or otherwise making the changes easy to include. I don't know does Google Code make it easy to merge changes from your fork. (Moving the project to GitHub or elsewhere where pull requests are used would be a good idea at some point.)
Originally submitted to Google Code by bryan.oakley on 15 Oct 2012
I don't agree that real objects is the way to go, but I'm not going to let that stop this feature from being implemented.
I think you can use the 'hg graft' command to pull down the changeset prior to where I added the proxies. If that doesn't work for you I can create a patch.
Could you also clarify why you think using proxies is better than using the real objects? I would really like to make this a power-user interface. I could see proxies implemented outside the core framework, though.
Originally submitted to Google Code by bryan.oakley on 15 Oct 2012
The main advantage I see to using proxies is that it provides a cleaner user interface for people who want to write listeners using this new API. The listener API is a user interface, and should be designed with the end user in mind. The real objects are complex and hard to understand, the proxy objects are simple and easy to understand. I see value in that.
The proxies allow the interface to be normalized and streamlined. For example, all proxy objects have a "longname" attribute and a "source" attribute even though not all of the core objects do. Sure, you could add this attribute to the core objects in 2.8, but with the proxy objects you're free to do whatever you want in 2.8 without adversely affecting people who use this interface. Going forward, you don't have to worry that a change to a core object might break some listener out in the wild -- breaking compatibility will be a conscious choice rather than an accident waiting to happen.
You wrote in comment 8 "If we pass the real objects, this listener API itself doesn't need to change at all.". That is true only from the perspective of the producer side of the API. From the consumer point of view, everything might change. You might decide to add or remove attributes or methods to the core objects. With a proxy, there's a greater chance that it won't have to change at all for the end user.
The proxies can still provide the power of the full objects, contrary to point 2 in comment 8. In the current implementation the actual objects are stored as a private attribute, but that could easily be made into a public attribute. With that you get the best of both worlds -- a streamlined interface for the general case, and the actual objects for the power user.
As for the documentation issue raised in comment 8, I think proxies make the documentation problem smaller rather than bigger. The proxies will be easy to document, just like all the other classes. If you don't use proxies, you'll have to sprinkle caveats in the documentation for the real objects ("Don't use this method in a listener", "Don't change this attribute from a listener", etc).
I agree that the current objects are complex and hard to understand, but one of the main targets of RF 2.8 will be making them much better. We have already replaced objects used for presenting test results internally with a new model that has a really nice API:
>>> from robot.model import TestCase
>>> tc = TestCase(name='Example', tags=['t1', 't2'])
>>> print tc.name, tc.tags
Example [t1, t2]
>>> kw = tc.keywords.create(name='Example Keyword', args=['a1', 'a2'])
>>> list(tc.keywords)
[<robot.model.keyword.Keyword object at 0xb77c3844>]
>>> tc.keywords[0] is kw
True
>>> print kw.name, kw.args
Example Keyword ['a1', 'a2']
>>> print [a for a in dir(tc) if a[0] != '']
['critical', 'doc', 'id', 'keyword_class', 'keywords', 'longname', 'name', 'parent', 'tags', 'timeout', 'visit']
>>> print [a for a in dir(kw) if a[0] != '' and not a.isupper()]
['args', 'doc', 'id', 'keywords', 'message_class', 'messages', 'name', 'parent', 'timeout', 'type', 'visit']
The real problem for users of this new listener API is that the API provided by these objects is going to change so much. If we are afraid of that, the easy solution is adding the new listener API only in RF 2.8 when the API provided by the objects is both better and stable. That actually was the comment other Robot core devs had when I discussed this with them. I would be willing to add the listener API already now, though, and just document that the objects are going to change. Users could then create their own compatibility layer on top of them if needed.
After finishing the last comment I realized that the big changes for how tests are executed internally in RF 2.8 might actually make the proposed new listener API less useful. The new robot.running model objects are likely to not have attributes like status or message anymore. The plan is that these objects themselves would not change at all during execution, but instead results were collected to separate results objects.
These are just vague plans at the moment, but odds are that robot.running is going to change even more than anticipated in above comments. It might really be better to postpone adding the new listener API until we know how robot.running actually looks like in the future.
This new functionality is finally documented. Can you @jussimalinen review the docs? Comments from others would be very highly appreciated too, but unfortunately generated docs aren't available anywhere until beta 1 is released.
Once someone else has looked at the docs this issue can be considered done and beta 1 created. I will briefly look at start/end_keyword methods after the beta, but I'm still afraid they need to wait for 3.1 or 3.0.1.
changed the title [-]New listener API that gets real suite/test objects as arguments[/-][+]New listener API that gets real suite/test objects as arguments and can modify them[/+]on Dec 22, 2015
Perhaps it's more an API documentation issue but would it be possible to list all object atributes where user can influence from listener interface. Or link to corresponding unit/acceptance test, to provide examples.
I didn't quite understand, why the first argument was called data. In my mind it didn't describe what the argument receives. Would runner or model describe better the argument. Or use suite and test as argument names in corresponding situation.
It's definitely more of a API documentation issue to explain attributes of the various model objects. It would probably be best to handle that as a separate issue listing attributes and other topics that needs documentation or that have documentation that could be enhanced. Even better if such an issue would be backed by a pull request.
Related to the new listener API, I think it is best to document what you cannot change. The biggest limitations are that changing the current data model doesn't change results because the result model has already been created (you should update result instead) and that trying to change results when related information is already written to output.xml doesn't work either. These both are documented in the UG, but I'm open for ideas how to enhance the documentation.
I'm not particularly happy with the attribute name data in listener v3 method documentation but other options aren't that good either. It was initially model, but that is somewhat confusing because it is a data model and the other argument is a result model. It cannot really be suite/test either, because the other argument also represent a suite or test. Notice that in the examples I actually used suite/test with that model object that was actually used.
I gave a new look at implementing start_keyword and end_keyword listener methods and my conclusion is that they needs to wait until RF 3.1 or later. It will require quite a bit refactoring, but I'm sure it would drive the internal design to better direction and would be worth it.
I consider this issue now done in RF 3.0 context. Enhancements to docs are obviously still possible.
I did look the acceptance tests, the examples in the documentation are clearer and better. Writing separate issues about API and listener documentation is good idea.
Adding start/end_keyword methods turned out to be even bigger task than anticipated, but it was finally done in RF 7.0 (#3296). After that the listener version 3 still lacks methods related to imports, but they are planned to be added in RF 7.1 (#5008).
Activity
spooning commentedon Jun 29, 2014
Sounds good to me. Patch with implementation, tests, and documentation needed.
spooning commentedon Jun 29, 2014
After implementing this on my machine, I think we can do better. Instead of passing in a suite, testcase, or keyword depending on the method, why not have a single "test run" object that contains all of that information? For example:
Of course, these values could be None depending on the context. For example, testrun.testcase and testrun.keyword would be None when start_suite and end_suite are called.
I like this better because it's easy to document (and thus easier to learn and use), and because it's more extensible. We can evolve the Testrun class over time to include other information that might be useful to the listener interface (eg: namespace, current statistics, etc). This makes it really easy to pass more information to the listener without having to add yet another listener api.
Another advantage is that if the test runner ever changed to support debugging features such as skipping or rerunning tests or keywords, etc, that functionality can be implemented via this object without having to add yet another listener interface. For example, maybe a listener could cause the current suite to abort with "testrun.abort('killed by the listener')". Obviously this means that the Testrun class is tightly coupled to the test runner, but better than that trying to put that coupling deeper, at the suite, test and keyword object layer.
spooning commentedon Jun 29, 2014
I've implemented this in a clone of robotframework. Any chance this could get merged into 2.7.5?
The documentation is a little weak but it's enough to get started. I would be happy to clean it up, and fix any issues with it or the code before it is released. I've implemented a simple acceptance test for it as well.
https://code.google.com/r/bryanoakley-listener3/
spooning commentedon Jun 29, 2014
Cool! I'll target this to 2.7.5 initially but cannot yet promise it will make it.
Is there a way for me to easily see changes you have done so that I could review the changes?
spooning commentedon Jun 29, 2014
You can clone the repository, or browse it from google code.
The original changeset is here:
https://code.google.com/r/bryanoakley-listener3/source/detail?r=1b0657486a0270b1eea7d4e5497128626c434944
I've updated the code to use proxy objects in the TestRun object, rather than the actual objexts. This way we can control exactly what gets pushed to the listener. The changelog where I added the proxies is here:
https://code.google.com/r/bryanoakley-listener3/source/detail?spec=svn014f0e3e87cc9acf500e6fb91ef00145fdcc2714&r=014f0e3e87cc9acf500e6fb91ef00145fdcc2714
spooning commentedon Jun 29, 2014
One rather big problem with the proposed listener API is that the objects to be passed are going to change heavily in RF 2.8 ( issue 825 ). It's unclear how the new objects will look like and I don't want to make any backwards compatibility promises related to them. This doesn't mean the API couldn't be added, but the documentation should clearly state that the objects passed in are going to change.
In my opinion it is better to send the real objects to the listener instead of proxies. That way there is no need to update the proxies in RF 2.8. It would also ease documenting the objects, because the objects are already documented at http://robot-framework.readthedocs.org/en/2.7.4/autodoc/robot.running.html
spooning commentedon Jun 29, 2014
With or without proxies, I think it's perfectly acceptable to say this interface could change when 2.8 comes out, as long as you don't remove any of the functionality that's already there.... I like the proxies because it gives you more freedom in what you do for 2.8, knowing that the listeners will receive a streamlined proxy object that has none of the internal attributes and methods necessary for the test to run.
My original implementation didn't use proxies, and that certainly gives more power to the listener. I'm never against having more power! Plus, if you add some cool new feature to the actual object you don't have to remember to update the proxy to provide the same feature to the listener. I think it comes down to whether you want a lean interface that can withstand a lot of changes to the internal objects, or a rich interface that may break (or at least change) from release to release.
I really appreciate you considering putting this in 2.7.5. If there's anything else I can do to help make that happen, let me know.
spooning commentedon Jun 29, 2014
Proxies have, in my opinion, following problems:
They need to be updated in 2.8. If we pass the real objects, this listener API itself doesn't need to change at all. Passed objects change obviously change, but if this possibility is documented clearly users can take it into account. You could, for example, create needed proxies on your own listeners.
As you pointed out, proxies take some of the power away from the API. You would be limited to the functionality provided by them. This would probably also lead to further enhancements to add more functionality to them in the future.
Proxies need to be documented and the documentation updated when there are changes. Real objects are already documented in the API docs at http://robot-framework.readthedocs.org/. When the APIs are enhanced in 2.8, the plan is to enhance the docs too.
If we agree that using real objects is the way to go, getting this enhancement into 2.7.5 ought to be possible. The best way to help with that is creating a patch with the required changes or otherwise making the changes easy to include. I don't know does Google Code make it easy to merge changes from your fork. (Moving the project to GitHub or elsewhere where pull requests are used would be a good idea at some point.)
spooning commentedon Jun 29, 2014
I don't agree that real objects is the way to go, but I'm not going to let that stop this feature from being implemented.
I think you can use the 'hg graft' command to pull down the changeset prior to where I added the proxies. If that doesn't work for you I can create a patch.
spooning commentedon Jun 29, 2014
If we go on with proxies, are you willing to update them in RF 2.8? And to add features requested elsewhere so that they provide more functionality?
Didn't know about
hg graft(and needed to upgrade to Mercurial 2.x to get it). I'll see how it works later.spooning commentedon Jun 29, 2014
yes.
spooning commentedon Jun 29, 2014
Could you also clarify why you think using proxies is better than using the real objects? I would really like to make this a power-user interface. I could see proxies implemented outside the core framework, though.
spooning commentedon Jun 29, 2014
The main advantage I see to using proxies is that it provides a cleaner user interface for people who want to write listeners using this new API. The listener API is a user interface, and should be designed with the end user in mind. The real objects are complex and hard to understand, the proxy objects are simple and easy to understand. I see value in that.
The proxies allow the interface to be normalized and streamlined. For example, all proxy objects have a "longname" attribute and a "source" attribute even though not all of the core objects do. Sure, you could add this attribute to the core objects in 2.8, but with the proxy objects you're free to do whatever you want in 2.8 without adversely affecting people who use this interface. Going forward, you don't have to worry that a change to a core object might break some listener out in the wild -- breaking compatibility will be a conscious choice rather than an accident waiting to happen.
You wrote in comment 8 "If we pass the real objects, this listener API itself doesn't need to change at all.". That is true only from the perspective of the producer side of the API. From the consumer point of view, everything might change. You might decide to add or remove attributes or methods to the core objects. With a proxy, there's a greater chance that it won't have to change at all for the end user.
The proxies can still provide the power of the full objects, contrary to point 2 in comment 8. In the current implementation the actual objects are stored as a private attribute, but that could easily be made into a public attribute. With that you get the best of both worlds -- a streamlined interface for the general case, and the actual objects for the power user.
As for the documentation issue raised in comment 8, I think proxies make the documentation problem smaller rather than bigger. The proxies will be easy to document, just like all the other classes. If you don't use proxies, you'll have to sprinkle caveats in the documentation for the real objects ("Don't use this method in a listener", "Don't change this attribute from a listener", etc).
spooning commentedon Jun 29, 2014
I agree that the current objects are complex and hard to understand, but one of the main targets of RF 2.8 will be making them much better. We have already replaced objects used for presenting test results internally with a new model that has a really nice API:
>>> from robot.model import TestCase
>>> tc = TestCase(name='Example', tags=['t1', 't2'])
>>> print tc.name, tc.tags
Example [t1, t2]
>>> kw = tc.keywords.create(name='Example Keyword', args=['a1', 'a2'])
>>> list(tc.keywords)
[<robot.model.keyword.Keyword object at 0xb77c3844>]
>>> tc.keywords[0] is kw
True
>>> print kw.name, kw.args
Example Keyword ['a1', 'a2']
>>> print [a for a in dir(tc) if a[0] != '']
['critical', 'doc', 'id', 'keyword_class', 'keywords', 'longname', 'name', 'parent', 'tags', 'timeout', 'visit']
>>> print [a for a in dir(kw) if a[0] != '' and not a.isupper()]
['args', 'doc', 'id', 'keywords', 'message_class', 'messages', 'name', 'parent', 'timeout', 'type', 'visit']
For more information about the new model see http://robot-framework.readthedocs.org/en/2.7.4/autodoc/robot.model.html. As noted on the docs, the plan is to use the same model with robot.running package in RF 2.8 and I definitely don't want any extra layer on top of it. I can see, for example, interesting use cases for being able to create tests or keywords dynamically (see
tc.keywords.createabove). Implementing proxies that support all the same functionality as the new model would be both a big task and provide no real benefits over using those objects directly.The real problem for users of this new listener API is that the API provided by these objects is going to change so much. If we are afraid of that, the easy solution is adding the new listener API only in RF 2.8 when the API provided by the objects is both better and stable. That actually was the comment other Robot core devs had when I discussed this with them. I would be willing to add the listener API already now, though, and just document that the objects are going to change. Users could then create their own compatibility layer on top of them if needed.
spooning commentedon Jun 29, 2014
After finishing the last comment I realized that the big changes for how tests are executed internally in RF 2.8 might actually make the proposed new listener API less useful. The new robot.running model objects are likely to not have attributes like status or message anymore. The plan is that these objects themselves would not change at all during execution, but instead results were collected to separate results objects.
These are just vague plans at the moment, but odds are that robot.running is going to change even more than anticipated in above comments. It might really be better to postpone adding the new listener API until we know how robot.running actually looks like in the future.
41 remaining items
pekkaklarck commentedon Dec 22, 2015
This new functionality is finally documented. Can you @jussimalinen review the docs? Comments from others would be very highly appreciated too, but unfortunately generated docs aren't available anywhere until beta 1 is released.
Once someone else has looked at the docs this issue can be considered done and beta 1 created. I will briefly look at
start/end_keywordmethods after the beta, but I'm still afraid they need to wait for 3.1 or 3.0.1.jussimalinen commentedon Dec 22, 2015
Read through the docs on iphone. Wrote a couple of line comments because modification on phone did not seem too fun. Looks good I would say.
[-]New listener API that gets real suite/test objects as arguments[/-][+]New listener API that gets real suite/test objects as arguments and can modify them[/+]Fix typos in listener v3 docs spotted by @jussimalinen. #1208
pekkaklarck commentedon Dec 22, 2015
Beta 1 is out and the new listener version documentation visible here:
http://robotframework.org/robotframework/3.0b1/RobotFrameworkUserGuide.html#listener-interface
Feedback welcome!
aaltat commentedon Dec 23, 2015
Perhaps it's more an API documentation issue but would it be possible to list all object atributes where user can influence from listener interface. Or link to corresponding unit/acceptance test, to provide examples.
I didn't quite understand, why the first argument was called data. In my mind it didn't describe what the argument receives. Would runner or model describe better the argument. Or use suite and test as argument names in corresponding situation.
pekkaklarck commentedon Dec 23, 2015
Thanks for the feedback @aaltat.
It's definitely more of a API documentation issue to explain attributes of the various model objects. It would probably be best to handle that as a separate issue listing attributes and other topics that needs documentation or that have documentation that could be enhanced. Even better if such an issue would be backed by a pull request.
Related to the new listener API, I think it is best to document what you cannot change. The biggest limitations are that changing the current data model doesn't change results because the result model has already been created (you should update result instead) and that trying to change results when related information is already written to output.xml doesn't work either. These both are documented in the UG, but I'm open for ideas how to enhance the documentation.
I was initially thinking about adding a link to the acceptance tests from the UG, but in the end I thought the included examples already covered everything and were much more simpler. If you think they would be useful, I can consider adding them, but we can also consider adding more examples. Tests and listener that are used for testing this functionality are here:
https://github.com/robotframework/robotframework/blob/master/atest/robot/output/listener_interface/listener_v3.robot
https://github.com/robotframework/robotframework/blob/master/atest/testdata/output/listeners/v3.py
I'm not particularly happy with the attribute name
datain listener v3 method documentation but other options aren't that good either. It was initiallymodel, but that is somewhat confusing because it is a data model and the other argument is a result model. It cannot really besuite/testeither, because the other argument also represent a suite or test. Notice that in the examples I actually usedsuite/testwith that model object that was actually used.pekkaklarck commentedon Dec 23, 2015
I gave a new look at implementing
start_keywordandend_keywordlistener methods and my conclusion is that they needs to wait until RF 3.1 or later. It will require quite a bit refactoring, but I'm sure it would drive the internal design to better direction and would be worth it.I consider this issue now done in RF 3.0 context. Enhancements to docs are obviously still possible.
aaltat commentedon Dec 24, 2015
I did look the acceptance tests, the examples in the documentation are clearer and better. Writing separate issues about API and listener documentation is good idea.
pekkaklarck commentedon Dec 27, 2015
Added #2279 about enhancing API docs. I try to get that done still before RF 3.0 final.
pekkaklarck commentedon Dec 29, 2015
API docs have now been enhanced. Comments would be appreciated. See #2279 for details.
pekkaklarck commentedon Jan 10, 2024
Adding
start/end_keywordmethods turned out to be even bigger task than anticipated, but it was finally done in RF 7.0 (#3296). After that the listener version 3 still lacks methods related to imports, but they are planned to be added in RF 7.1 (#5008).