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
Support programmatic modifications of test data and results as part of normal execution #1976
There are many command line options to alter the parsed test suite structure before executing it. You can, for example, use --name and --doc to set new name and documentation, respectively, or use --test, --suite, --include and --exclude to select which tests to execute. There are, however, sometimes needs for custom modifications.
For example, a team at Nokia recently wanted to way to run only every Xth test in one test run. This isn't supported using any command line options, but programmatically Robot's public APIs make the basic implementation pretty simple:
A problem with the above solution is that it only runs tests and doesn't create logs and reports, but that would be pretty easy to implement too. A much bigger is that this script doesn't take same arguments as pybot does, and handling all same arguments would be a really big task.
A pretty simple but generic and powerful solution would be allowing registering visitors like RemoveEveryXthTest above to be used after parsing tests but before running them. This could work similarly as when registering listeners that get notifications during test execution:
pybot --visitor RemoveEveryXthTest:2 tests.robot
The :2 part of the the visitor name would specify arguments passed to the visitors __init__ same way listeners accept them.
Would this function run exactly once before the tests start running?
Instead, what about making it possible to define a function to be called immediately before running each test? That function could return True or False, and if False, that test is skipped? That would let you do everything described in this feature, plus allow dynamic skipping of tests.
Yes, this is executed once before execution. There are also other use cases than dropping certain tests.
I think modifications during execution are better done using the listener API. It obviously needed to be enhanced somehow to make dropping tests possible.
So, using this interface could you programmatically build suites/tests? That would be extremely cool and something I've wanted to be able to do for a while.
Also, skipping tests/changing the results of a test should definitely be doable from the listener interface.
You can build tests already now, but then you need to also take care of running tests, creating logs, etc. This API is planned to allow pre-run modifications so that execution etc. would be like normally.
What should the command line option to enable this be called? --visitor I used in earlier examples is too generic. My best idea so far is --prerunvisitor or --previsitor.
It's going to be used to initialize the test run, so something along the
lines of "--init" or "--initfunc" or "--initializer" makes sense to me.
On Thu, May 28, 2015 at 4:15 PM, Pekka Klärck [email protected]
wrote:
What should the command line option to enable this be called? --visitor I
used in earlier examples is too generic. My best idea so far is
--prerunvisitor or --previsitor.
—
Reply to this email directly or view it on GitHub #1976 (comment)
.
I think --init is a bit too generic. The current implementation uses --prerunvisitor, but that visitor part doesn't really tell much. Perhaps something like --prerunmodifier would be better. It's pretty long, but options can be shortened (e.g. --prerun) when used as long as they are unique.
I've also been thinking should we add similar --postrunmodifier to allow modifying results before logs and reports are created. It could also be used with Rebot, so perhaps it should be --prerebotmodifier in both sides.
changed the title [-]Support custom modifications of test data and results[/-][+]Support programmatic modifications of test data and results as part of normal run[/+]on Jun 3, 2015
changed the title [-]Support programmatic modifications of test data and results as part of normal run[/-][+]Support programmatic modifications of test data and results as part of normal execution[/+]on Jun 3, 2015
This issue is now ready for review. Especially new docs committed in ce4d5fa (visitor API docs), b26a664 (User Guide) and 54ad854 (--help) should be proof-read.
Review by anyone is more than appreciated, but I leave it for @jussimalinen to close this issue when he's reviewed the changes.
Could you please clarify what this change currently supports? You say at one point that this occurs once before exceution, but then you mention the Listener interface needs to be enhanced. Does that mean that a keyword/test/suite listener can now make modifications on a listener event, or is that something tied to a different enhancement, or something not yet captured?
Could you @davekipfer take a look at it and see is it adequate? If it isn't, please submit a new issue and tell what you don't understand and we'll enhance docs.
Activity
pekkaklarck commentedon Apr 23, 2015
Things to consider:
robot.runandTestSuite.run. This support is currently planned for listeners in Allow giving listener and model modifier instances torobot.runandTestSuite.run#1969.boakley commentedon May 11, 2015
Would this function run exactly once before the tests start running?
Instead, what about making it possible to define a function to be called immediately before running each test? That function could return True or False, and if False, that test is skipped? That would let you do everything described in this feature, plus allow dynamic skipping of tests.
pekkaklarck commentedon May 11, 2015
Yes, this is executed once before execution. There are also other use cases than dropping certain tests.
I think modifications during execution are better done using the listener API. It obviously needed to be enhanced somehow to make dropping tests possible.
just-be-dev commentedon May 24, 2015
So, using this interface could you programmatically build suites/tests? That would be extremely cool and something I've wanted to be able to do for a while.
Also, skipping tests/changing the results of a test should definitely be doable from the listener interface.
pekkaklarck commentedon May 24, 2015
You can build tests already now, but then you need to also take care of running tests, creating logs, etc. This API is planned to allow pre-run modifications so that execution etc. would be like normally.
just-be-dev commentedon May 24, 2015
Right, that's more what I mean. I know I can build them, but it's very cumbersome to add them in to normal test execution.
pekkaklarck commentedon May 28, 2015
What should the command line option to enable this be called?
--visitorI used in earlier examples is too generic. My best idea so far is--prerunvisitoror--previsitor.boakley commentedon May 28, 2015
It's going to be used to initialize the test run, so something along the
lines of "--init" or "--initfunc" or "--initializer" makes sense to me.
On Thu, May 28, 2015 at 4:15 PM, Pekka Klärck [email protected]
wrote:
Support custom modifications of test data before execution (#1976).
pekkaklarck commentedon May 29, 2015
I think
--initis a bit too generic. The current implementation uses--prerunvisitor, but that visitor part doesn't really tell much. Perhaps something like--prerunmodifierwould be better. It's pretty long, but options can be shortened (e.g.--prerun) when used as long as they are unique.I've also been thinking should we add similar
--postrunmodifierto allow modifying results before logs and reports are created. It could also be used with Rebot, so perhaps it should be--prerebotmodifierin both sides.just-be-dev commentedon May 29, 2015
Sounds good to me.
4 remaining items
Model modifier enhancements. #1976
[-]Support custom modifications of test data and results[/-][+]Support programmatic modifications of test data and results as part of normal run[/+]pekkaklarck commentedon Jun 3, 2015
Here's an example of a modifier that selects only every Xth test. It would work both with
--prerunmodifierand--prerebotmodifier.[-]Support programmatic modifications of test data and results as part of normal run[/-][+]Support programmatic modifications of test data and results as part of normal execution[/+]Enhanced visitor interface documentation.
UG: Documented new --pre(run|rebot)modifier options (#1976).
--help: Documented new --pre(run|rebot)modifier options (#1976).
pekkaklarck commentedon Jun 4, 2015
This issue is now ready for review. Especially new docs committed in ce4d5fa (visitor API docs), b26a664 (User Guide) and 54ad854 (--help) should be proof-read.
Review by anyone is more than appreciated, but I leave it for @jussimalinen to close this issue when he's reviewed the changes.
jussimalinen commentedon Jun 5, 2015
Looks good.
davekipfer commentedon Jul 31, 2015
Could you please clarify what this change currently supports? You say at one point that this occurs once before exceution, but then you mention the Listener interface needs to be enhanced. Does that mean that a keyword/test/suite listener can now make modifications on a listener event, or is that something tied to a different enhancement, or something not yet captured?
pekkaklarck commentedon Jul 31, 2015
This functionality is documented in the User Guide:
http://robotframework.org/robotframework/2.9/RobotFrameworkUserGuide.html#programmatic-modification-of-test-data
Could you @davekipfer take a look at it and see is it adequate? If it isn't, please submit a new issue and tell what you don't understand and we'll enhance docs.