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
If multiple keywords match, resolve conflict first using search order #4609
The changes for fixing issue #4366 changed the Set Library Search Order functionality in a way that it cannot be used to force keywords to be used from imported resources if a keyword with same name exists in the importing resource file (or a testsuite in the future version?)
We have an old library (develop originally for RF 3.0) that enable us to created mocked user keywords to be used in user keyword “unit tests”. With this we can replace some of the user keywords (in the same resource file or testsuite) in a user keyword under test with a mocks and only concentrate on the functionality on that keyword. Just the default unit test approaches.
Now that local keywords cannot be overridden from the imported resource files, even using Set Library Search Order, this approach has now become impossible.
Related issue.
BuiltIn library does not have keyword for getting currently set search order. This is a bit inconvenient for our library. Fake keywords (and implementing resources/libraries) can be set in different stages, so it is a bit hard to keep track of currently active search order. It would be lot easier if it could be asked from robot itself.
I guess Set Library Search Order could be called with some dummy value (or None) to get the current value and then set it back (maybe with some modification) but it would look a bit cumbersome.
(In the original implementation we are using internals from BuiltIn to get this information but this is definitely not something that should be done)
I mentioned our library search order issue in RoboCon 2023: Extending Robot Framework workshop - @pekkaklarck had a quick glance at code and it looked like a change to the order of if statements (determining the library to call) would solve the issue to our benefit.
Any chance to get the solution verified and in before RF 7?
Do I get it right that you'd like search order to be used first and only then keywords searched from the same file? That ought to be fine and as @ursah commented shouldn't be too hard to implement. The related code looks like
and it would be easy to change the order so that filtering based on search order is done first. Can you test that locally and see how the results look like? If that fixes your issue, I can see are there some acceptance tests that fail if the logic is changed and are those tests so important that the change isn't possible. Other things to take into account:
The above code is related to finding keywords from a resource file. There's similar code for finding keywords from libraries that would need to be updated as well.
Private keywords probably shouldn't have precedence over public keywords even if they'd be first in search order. That may require a bit bigger changes.
you'd like search order to be used first and only then keywords searched from the same file
Yes, we can try this out. Just making it sure that I understand this correctly.
We should test it this way? Or what would be the correct order
if len(handlers) > 1:
handlers = self._filter_based_on_search_order(handlers)
if len(handlers) > 1:
handlers = self._prioritize_same_file_or_public(handlers)
if len(handlers) > 1:
handlers = self._select_best_matches(handlers)
For libraries it sould be like this?:
if len(handlers) > 1:
handlers = self._filter_based_on_search_order(handlers)
if len(handlers) > 1:
handlers = self._select_best_matches(handlers)
if len(handlers) > 1:
handlers, pre_run_message = self._filter_stdlib_handler(handlers)
Private keywords (those from RF6 ->?).
We have no experience with those yet so can't really say this or that.
Obviously, as we haven't had a change to use them yet they wouldn't be a problem.
But once we get to know them and how we could use them then it might come as an issue.
We do have concept of "private keyword" (marked as leading underscore). If we would start tagging those private maybe we run into some issues in our code base.
BTW.
Would it make sense to implement Get Library Search Order keyword in BuiltIn()?
Now that we are manipulating this search order it is difficult to keep track what is currently active.
Of course we can set dummy value to get current and then set it back but doesn't look that clean code.
Could you try running Robot's acceptance tests with this change to see does it break something unexpected? If not, this could possibly still be changed in RF 6.1.
Got the below 6 fails from acceptance tests. The changes were as @jyrlindr proposes above.
All seem to be related to search order.
Name
×Documentation
×Tags
Status
×Message
×Elapsed
×Start / End
Robot . Keywords . Embedded Arguments Conflicts . Best match in library wins over search order
FAIL
Status of 'Best match in library wins over search order' should have been PASS but it was FAIL. Error message: AssertionError
00:00:00.002
20230327 10:39:27.29420230327 10:39:27.296
Robot . Keywords . Embedded Arguments Conflicts . Best match in resource wins over search order
FAIL
Status of 'Best match in resource wins over search order' should have been PASS but it was FAIL. Error message: Best match != Match
00:00:00.002
20230327 10:39:27.29020230327 10:39:27.292
Robot . Keywords . Keyword Namespaces . Local keyword in resource file has precedence even if search order is set
FAIL
Wrong log message: Keyword in resource 1 != Keyword in resource 2
00:00:00.006
20230327 10:39:30.47020230327 10:39:30.476
Robot . Keywords . Private . Local Private Keyword In Resource File Has Precedence Even If Search Order Is Set
FAIL
Status of 'Local Private Keyword In Resource File Has Precedence Even If Search Order Is Set' should have been PASS but it was FAIL. Error message: Not executed
00:00:00.003
20230327 10:39:41.75420230327 10:39:41.757
Robot . Standard Libraries . Builtin . Set Library Search Order . Exact match wins over match containing embedded arguments regardless search order
FAIL
Status of 'Exact match wins over match containing embedded arguments regardless search order' should have been PASS but it was FAIL. Error message: Should not be run due to keywords with normal arguments having higher precedence.
00:00:00.001
20230327 10:47:04.01620230327 10:47:04.017
Robot . Standard Libraries . Builtin . Set Resource Search Order . Exact match wins over match containing embedded arguments regardless search order
FAIL
Status of 'Exact match wins over match containing embedded arguments regardless search order' should have been PASS but it was FAIL. Error message: Should not be run due to keywords with normal arguments having higher precedence
Could someone create a pull request with the change? The PR should preferably also contain test fixes. I'm not sure are new tests needed, but the existing failing ones should be renamed appropriately.
changed the title [-]Allow Set Library Search Order to override the local keywords precedence.[/-][+]Use library search order first for resolving conflicts if there are multiple matching keywords[/+]on May 17, 2023
changed the title [-]Use library search order first for resolving conflicts if there are multiple matching keywords[/-][+]Resolve conflict first using search order if multiple keywords match[/+]on May 17, 2023
changed the title [-]Resolve conflict first using search order if multiple keywords match[/-][+]If multiple keywords match, resolve conflict first using search order[/+]on Jun 5, 2023
Activity
ursah commentedon Feb 28, 2023
I mentioned our library search order issue in RoboCon 2023: Extending Robot Framework workshop - @pekkaklarck had a quick glance at code and it looked like a change to the order of if statements (determining the library to call) would solve the issue to our benefit.
Any chance to get the solution verified and in before RF 7?
pekkaklarck commentedon Mar 1, 2023
Do I get it right that you'd like search order to be used first and only then keywords searched from the same file? That ought to be fine and as @ursah commented shouldn't be too hard to implement. The related code looks like
and it would be easy to change the order so that filtering based on search order is done first. Can you test that locally and see how the results look like? If that fixes your issue, I can see are there some acceptance tests that fail if the logic is changed and are those tests so important that the change isn't possible. Other things to take into account:
jyligehc commentedon Mar 1, 2023
Thanks Pekka for your response.
This is correct:
Yes, we can try this out. Just making it sure that I understand this correctly.
We should test it this way? Or what would be the correct order
For libraries it sould be like this?:
Private keywords (those from RF6 ->?).
We have no experience with those yet so can't really say this or that.
Obviously, as we haven't had a change to use them yet they wouldn't be a problem.
But once we get to know them and how we could use them then it might come as an issue.
We do have concept of "private keyword" (marked as leading underscore). If we would start tagging those private maybe we run into some issues in our code base.
jyligehc commentedon Mar 1, 2023
BTW.
Would it make sense to implement
Get Library Search Orderkeyword in BuiltIn()?Now that we are manipulating this search order it is difficult to keep track what is currently active.
Of course we can set dummy value to get current and then set it back but doesn't look that clean code.
pekkaklarck commentedon Mar 1, 2023
Yeah, have that
_filter_based_on_search_orderfirst. If it works for you, we need to think what kind of implications it would have for others.Adding
Get Library Search Ordersounds good to me. Please submit a separate issue about that.jyligehc commentedon Mar 2, 2023
We did try this with above changes and it seemed to work as expected.
I'll create a separate issue for
Get library Search Order.pekkaklarck commentedon Mar 24, 2023
Could you try running Robot's acceptance tests with this change to see does it break something unexpected? If not, this could possibly still be changed in RF 6.1.
ursah commentedon Mar 28, 2023
Got the below 6 fails from acceptance tests. The changes were as @jyrlindr proposes above.
All seem to be related to search order.
ursah commentedon Apr 6, 2023
@pekkaklarck Anything else we could help with to get the library search order change released?
pekkaklarck commentedon Apr 18, 2023
Could someone create a pull request with the change? The PR should preferably also contain test fixes. I'm not sure are new tests needed, but the existing failing ones should be renamed appropriately.
Allow Library Search Order to control precedence (robotframework#4609)
Update embedded argument conflict tests (robotframework#4609)
Update keyword namespaces tests (robotframework#4609)
Update private keyword tests (robotframework#4609)
Update resource search order tests (robotframework#4609)
4 remaining items
Add test for conflict due to search order (robotframework#4609)
[-]Allow Set Library Search Order to override the local keywords precedence.[/-][+]Use library search order first for resolving conflicts if there are multiple matching keywords[/+][-]Use library search order first for resolving conflicts if there are multiple matching keywords[/-][+]Resolve conflict first using search order if multiple keywords match[/+]pekkaklarck commentedon May 17, 2023
This was implemented in great PR #4760 by @ursa-h. Thanks for contribution!
ursa-h commentedon May 22, 2023
Nice, thank you @pekkaklarck! Kudos to @jyrlindr and the team for the code change and testing!
[-]Resolve conflict first using search order if multiple keywords match[/-][+]If multiple keywords match, resolve conflict first using search order[/+]