Add support for prefixing suite keywords with suite name#5584
Add support for prefixing suite keywords with suite name#5584sylvesterboris wants to merge 1 commit intorobotframework:masterfrom
Conversation
- Allow calling suite keywords with suite name prefix (e.g., MySuite.Some keyword) - Modified _get_explicit_runner() to check suite_file.owner.name - Maintains full backward compatibility with existing unprefixed calls - Fixes robotframework#5582
There was a problem hiding this comment.
Pull request overview
Adds support for resolving suite file user keywords using an explicit SuiteName.Keyword prefix by extending explicit keyword lookup in the runtime namespace resolution logic.
Changes:
- Update
_get_explicit_runner()to search suite-file keywords when the explicit prefix matches the current suite name. - Keep existing explicit lookup across imported libraries and resources.
Comments suppressed due to low confidence (1)
src/robot/running/namespace.py:523
- When
owner_namematches the suite name, this code still proceeds to search libraries/resources with the sameowner_name. If a library/resource shares the suite name and has the same keyword, this can newly produce multiple matches (or change precedence) compared to the previous behavior. Consider short-circuiting: if the suite name matches, first resolve suite keywords and return immediately when found (or skip searching other owners for thatowner_name) to avoid introducing ambiguity/regressions.
# Check suite file first (if suite name matches)
if (self.suite_file and self.suite_file.owner
and eq(self.suite_file.owner.name, owner_name)):
for kw in self.suite_file.find_keywords(kw_name):
kws_and_names.append((kw, kw_name))
# Then check libraries and resources
for owner in (*self.libraries.values(), *self.resources.values()):
if eq(owner.name, owner_name):
for kw in owner.find_keywords(kw_name):
kws_and_names.append((kw, kw_name))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _get_explicit_runner(self, name): | ||
| kws_and_names = [] | ||
| for owner_name, kw_name in self._get_owner_and_kw_names(name): | ||
| # Check suite file first (if suite name matches) | ||
| if (self.suite_file and self.suite_file.owner | ||
| and eq(self.suite_file.owner.name, owner_name)): | ||
| for kw in self.suite_file.find_keywords(kw_name): | ||
| kws_and_names.append((kw, kw_name)) |
There was a problem hiding this comment.
This introduces new keyword resolution behavior (allowing SuiteName.Keyword to resolve suite-file keywords). There doesn’t appear to be automated coverage around namespace keyword resolution in unit tests; please add an acceptance/unit test that exercises suite-prefixed suite keywords (and ideally a conflict case where a library/resource has the same name) to prevent regressions.
| if (self.suite_file and self.suite_file.owner | ||
| and eq(self.suite_file.owner.name, owner_name)): |
There was a problem hiding this comment.
The multi-line condition formatting here doesn’t match the Black-formatted style used elsewhere in this file (e.g., earlier elif ( blocks). Consider reformatting this if using Black’s standard multi-line parentheses layout to keep style consistent and avoid formatting-only diffs later.
| if (self.suite_file and self.suite_file.owner | |
| and eq(self.suite_file.owner.name, owner_name)): | |
| if ( | |
| self.suite_file | |
| and self.suite_file.owner | |
| and eq(self.suite_file.owner.name, owner_name) | |
| ): |
Solution
Modified the _get_explicit_runner() method in src/robot/running/namespace.py to also check the suite file's keywords when a prefix is used.
Key changes:
suite_file.owner.namebefore searching libraries/resourcesTesting
Verified with test case: