robotframework
robotframework copied to clipboard
Reloading user keywords within a suite
This use case might be rare but we are currently suffering from it. It relates to functionality where resource file can be loaded with using variables in the name like:
Resource system/${DEVICE}/common.resource
The problem arises when the value of the ${DEVICE}
is changed and the keywords from the new location needs to be loaded within the same suite. Normally, resource files are loaded when entering a suite and cannot be reloaded unlike libraries.
It is possible to load keywords from a new resource file using:
Import Resource system/${DEVICE}/common.resource
New keywords are added fine but if there are keywords with same names already been load, the RF starts to complain these keywords having the same name.
The Set Library Search Order
won’t fix this problem as it only possible to give it the filename (common.resource) which in above use case is the same.
There would be another way use variables in resource names:
Import Resource system/${DEVICE}_common.resource
But even now the Set Library Search Order
doesn’t seem to work as expected like if used in this ways:
Set Library Search Order ${DEVICE}_common.resource
Anyway using Set Library Search Order
would add complexity to the implementation and if there would be many “DEVICE” options you would end up loading lot of resource files with same keywords.
Nicest solution would be to have keyword similar to Reload Library: Reload Resources
Builtin.
This would reload all the resource file in a suite (and clearing previously loaded keywords) using updated variables in the resource filenames.
Some example code can be found here: rf-resource-issue
It's strange that the resource isn't imported again if the variable used in the path changes. One possibility is that we use the original resource file path, without variables being resolved, in a cache we use to avoid re-importing resources unnecessarily. That cache is causing issues also otherwise and it would probably be best to remove it altogether.
We already have #2099 about always reprocessing resource files when they are imported and this issue could be considered its duplicate. I just added it and similar issues related to libraries and variables to RF 8.0 scope, but cannot make promises will these issues actually be fixed as part of that release or when the release will be out.
If the problem with this issue is that we use wrong cache key, it could be possible to fix this issue already before we remove the whole cache. I thus leave this issue open separately from #2099.
Due to my paternity leave, I won't have time to investigate this further in the near future. If someone else has time and interest and finds a good solution, I'd be happy to review a PR.