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
Give local keywords precedence over imported keywords in resource files #4366
and also the imported another.resource contains keyword with name Internal Keyword, execution fails due to there being two keywords matching the same name. Failing like that would be fine if both matches were imported, but when a resource file has a local keyword matching the name it should have precedence.
This change would be good in general, but it gets more important when we add support for private keywords in resource files (#430). Public keywords will have precedence over private keywords otherwise, but keywords in the same resource files should call them automatically if there's a conflict.
The example in the description contains keyword Internal Keyword and another keyword Keyword that uses it. The idea of this issue is making sure Keyword would always call the local Internal Keyword even if there would be a keyword with the same name implemented elsewhere. There are three different places where such a keyword could be implemented:
In a library. This is something we don't need to care, because user keywords always have a higher precedence that libraries. Already now the local Internal Keyword would be called if there was a library having a keyword with the same name.
In another resource file. This currently causes an error due to there being multiple keywords with the same name. Fixing this situation so that a keyword in the same file is always called is the core of this issue. Because such a situation is currently an error, changing it wouldn't be backwards incompatible.
In the test case file using that resource file. This situation is problematic, because we currently give keywords in test case files the highest precedence. If you now have Internal Keyword in a test case file, it is unconditionally called instead of the local Internal Keyword. Changing this would thus change functionality and be a backwards incompatible change. I'll write another comment about that.
As discussed above, we currently give keywords in test case files the highest precedence. The motivation has been that tests always call keywords implemented in the same file even if keywords with same names would be elsewhere. That behavior is something we absolutely don't want to change.
This functionality also means that it is possible to override certain keywords implemented in resource files by having keywords with the same name in the test case file. That's a somewhat questionable and complicated use case. Keywords in a test case file accidentally overriding keywords resource files use can also cause really strange errors.
My opinion is that it would be better to change this that keywords in resource files would always use local keywords even if there would be a keyword with the same name in the test case file. That would be, however, a backwards incompatible change and doing them in a non-major release like RF 5.1 is generally not a good idea. I'll write another comment about alternatives we now have.
We need to make a decision how to handle a situation that a keyword in a resource file (e.g. Keyword in the example in the description) uses another keyword (e.g. Internal Keyword) so that there are implementations both in the same resource file and in the test case file. These are the alternatives:
Preserve the current behavior and always use the keyword in the test case file. Only favor local keywords if there's a keyword with the same name implemented in another resource file. This would be easy to implement and wouldn't have backwards incompatibility concerns. Local keywords not always having a precedence would be inconsistent, though.
Always give local keywords precedence over keywords implemented elsewhere, regardless where they are implemented. Change this already in RF 5.1 even though the change is backwards incompatible.
Same as option 2 but with a deprecation period. In RF 5.1 we'd emit a warning if a keyword in a test case file is used over a local keyword in a resource file and in RF 5.2 (or possibly only in RF 6.0) we'd change the behavior.
I somewhat strongly prefer local keywords always having highest precedence which would rule the option 1 out. Deprecating this can be somewhat complicated and certainly adds extra work so I'd prefer option 2, but backwards incompatible change in a non-major version without a deprecation are so bad that I guess the option 3 is safest. What do others think about this?
Local keywords in resource files are now favored over imported keywords with same name. That was needed to enhance how private keywords (#430) work if there is also public keyword with the same name. Still need to decide do we want to favor local keywords over keywords in test cases files.
I opened a discussion about this on the #devel channel on our Slack and people in general favored local keywords always having precedence. I think that's a good goal, but changing the behavior in RF 5.1 so that keywords in test case files wouldn't anymore have the highest precedence is somewhat badly backwards incompatible. I thus decided to handle this so that test case file keywords will still have precedence also over local keywords in resource files but that is deprecated. The behavior can then be changed in RF 6.0.
Are there plans to be able to override this behavior on demand - by using special tags, or some other technique?
My use case - there is this high-level keyword in a resource file:
Do Operation X
General Flow A
General Flow B
General Flow C
, which covers the flow in most usages (99% of the cases). General Flow * are defined in the same resource file.
But in specific suites a sub-step is different (slightly modified/customized UI, or additional operation is needed, etc) and all the time I'm using RF I've been overriding it - e.g. General Flow B is redefined in that suite to cater to its custom needs.
Suite-level precedence allowed for that, and that was also what the guide described for scoping.
As I understand the change in v7 will break this pattern - thus the question, can the behavior be overriden on demand to the old one?
A question about the effect on variables' scope - when a variable is defined in a resource file, used in a keyword in that same file, and a suite imports the resource, does not override the keyword but declares the same variable with a new name - which value will the keyword use?
Its local (from the resource) or the redefined in the suite?
The use case is similar to my previous comment - a shared resource file that covers the majority of the usage, but in specific suites the operation a keyword provides is differet/customized and some of it variables are redefined (for example - UI operation with different locators; or a "file getter" with different source URI just for this suite).
Activity
pekkaklarck commentedon Jul 5, 2022
The example in the description contains keyword
Internal Keywordand another keywordKeywordthat uses it. The idea of this issue is making sureKeywordwould always call the localInternal Keywordeven if there would be a keyword with the same name implemented elsewhere. There are three different places where such a keyword could be implemented:In a library. This is something we don't need to care, because user keywords always have a higher precedence that libraries. Already now the local
Internal Keywordwould be called if there was a library having a keyword with the same name.In another resource file. This currently causes an error due to there being multiple keywords with the same name. Fixing this situation so that a keyword in the same file is always called is the core of this issue. Because such a situation is currently an error, changing it wouldn't be backwards incompatible.
In the test case file using that resource file. This situation is problematic, because we currently give keywords in test case files the highest precedence. If you now have
Internal Keywordin a test case file, it is unconditionally called instead of the localInternal Keyword. Changing this would thus change functionality and be a backwards incompatible change. I'll write another comment about that.pekkaklarck commentedon Jul 5, 2022
As discussed above, we currently give keywords in test case files the highest precedence. The motivation has been that tests always call keywords implemented in the same file even if keywords with same names would be elsewhere. That behavior is something we absolutely don't want to change.
This functionality also means that it is possible to override certain keywords implemented in resource files by having keywords with the same name in the test case file. That's a somewhat questionable and complicated use case. Keywords in a test case file accidentally overriding keywords resource files use can also cause really strange errors.
My opinion is that it would be better to change this that keywords in resource files would always use local keywords even if there would be a keyword with the same name in the test case file. That would be, however, a backwards incompatible change and doing them in a non-major release like RF 5.1 is generally not a good idea. I'll write another comment about alternatives we now have.
pekkaklarck commentedon Jul 5, 2022
We need to make a decision how to handle a situation that a keyword in a resource file (e.g.
Keywordin the example in the description) uses another keyword (e.g.Internal Keyword) so that there are implementations both in the same resource file and in the test case file. These are the alternatives:Preserve the current behavior and always use the keyword in the test case file. Only favor local keywords if there's a keyword with the same name implemented in another resource file. This would be easy to implement and wouldn't have backwards incompatibility concerns. Local keywords not always having a precedence would be inconsistent, though.
Always give local keywords precedence over keywords implemented elsewhere, regardless where they are implemented. Change this already in RF 5.1 even though the change is backwards incompatible.
Same as option 2 but with a deprecation period. In RF 5.1 we'd emit a warning if a keyword in a test case file is used over a local keyword in a resource file and in RF 5.2 (or possibly only in RF 6.0) we'd change the behavior.
I somewhat strongly prefer local keywords always having highest precedence which would rule the option 1 out. Deprecating this can be somewhat complicated and certainly adds extra work so I'd prefer option 2, but backwards incompatible change in a non-major version without a deprecation are so bad that I guess the option 3 is safest. What do others think about this?
aaltat commentedon Jul 5, 2022
I would go also with local keywords, it feels most natural when looking test data. But I don't feel strongly about it.
Give local keywords in resource precedence over imported keywords.
No warning if there is one public and one or more private keywords.
pekkaklarck commentedon Jul 5, 2022
Local keywords in resource files are now favored over imported keywords with same name. That was needed to enhance how private keywords (#430) work if there is also public keyword with the same name. Still need to decide do we want to favor local keywords over keywords in test cases files.
pekkaklarck commentedon Jul 11, 2022
I opened a discussion about this on the #devel channel on our Slack and people in general favored local keywords always having precedence. I think that's a good goal, but changing the behavior in RF 5.1 so that keywords in test case files wouldn't anymore have the highest precedence is somewhat badly backwards incompatible. I thus decided to handle this so that test case file keywords will still have precedence also over local keywords in resource files but that is deprecated. The behavior can then be changed in RF 6.0.
Give precedence to local and public kws over search order.
tminakov commentedon Mar 30, 2023
Are there plans to be able to override this behavior on demand - by using special tags, or some other technique?
My use case - there is this high-level keyword in a resource file:
, which covers the flow in most usages (99% of the cases).
General Flow *are defined in the same resource file.But in specific suites a sub-step is different (slightly modified/customized UI, or additional operation is needed, etc) and all the time I'm using RF I've been overriding it - e.g.
General Flow Bis redefined in that suite to cater to its custom needs.Suite-level precedence allowed for that, and that was also what the guide described for scoping.
As I understand the change in v7 will break this pattern - thus the question, can the behavior be overriden on demand to the old one?
tminakov commentedon Mar 30, 2023
A question about the effect on variables' scope - when a variable is defined in a resource file, used in a keyword in that same file, and a suite imports the resource, does not override the keyword but declares the same variable with a new name - which value will the keyword use?
Its local (from the resource) or the redefined in the suite?
The use case is similar to my previous comment - a shared resource file that covers the majority of the usage, but in specific suites the operation a keyword provides is differet/customized and some of it variables are redefined (for example - UI operation with different locators; or a "file getter" with different source URI just for this suite).