Skip to content

Add support for prefixing suite keywords with suite name#5584

Open
sylvesterboris wants to merge 1 commit intorobotframework:masterfrom
sylvesterboris:add-suite-keyword-prefix-support
Open

Add support for prefixing suite keywords with suite name#5584
sylvesterboris wants to merge 1 commit intorobotframework:masterfrom
sylvesterboris:add-suite-keyword-prefix-support

Conversation

@sylvesterboris
Copy link
Copy Markdown

@sylvesterboris sylvesterboris commented Dec 21, 2025

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:

  • Check suite_file.owner.name before searching libraries/resources
  • Added proper None checks for robustness
  • Suite keywords checked first, maintaining consistency with unprefixed resolution

Testing

Verified with test case:

*** Test Cases ***
Simple test
    Some keyword    123    
    MySuite.Some keyword    123    

*** Keywords ***
Some keyword
    [Arguments]        ${alpha}
    Log    ${alpha}    

- 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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_name matches the suite name, this code still proceeds to search libraries/resources with the same owner_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 that owner_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.

Comment on lines 511 to +518
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))
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +515 to +516
if (self.suite_file and self.suite_file.owner
and eq(self.suite_file.owner.name, owner_name)):
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)
):

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants