Skip to content

Commit

Permalink
Keyword should exist performance (#4457)
Browse files Browse the repository at this point in the history
Don't look for possible recommendations. Fixes #4470.
  • Loading branch information
JFoederer committed Sep 20, 2022
1 parent 78e3574 commit d9055f7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Keyword does not exist
Keyword does not exist with custom message
Check Test Case ${TESTNAME}

Recommendations not shown if keyword does not exist
Check Test Case ${TESTNAME}

Duplicate keywords
Check Test Case ${TESTNAME}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Keyword does not exist with custom message
[Documentation] FAIL Custom message
Non Existing Custom message

Recommendations not shown if keyword does not exist
[Documentation] FAIL No keyword with name 'should be eQQual' found.
should be eQQual

Duplicate keywords
[Documentation] FAIL
... Multiple keywords with name 'Duplicated keyword' found. \
Expand Down
2 changes: 1 addition & 1 deletion src/robot/libraries/BuiltIn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3266,7 +3266,7 @@ def keyword_should_exist(self, name, msg=None):
See also `Variable Should Exist`.
"""
try:
runner = self._namespace.get_runner(name)
runner = self._namespace.get_runner(name, recommend_on_failure=False)
except DataError as error:
raise AssertionError(msg or error.message)
if isinstance(runner, UserErrorHandler):
Expand Down
21 changes: 12 additions & 9 deletions src/robot/running/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ def reload_library(self, libname_or_instance):
library.reload()
return library

def get_runner(self, name):
def get_runner(self, name, recommend_on_failure=True):
try:
return self._kw_store.get_runner(name)
return self._kw_store.get_runner(name, recommend_on_failure)
except DataError as error:
return UserErrorHandler(error, name)

Expand Down Expand Up @@ -257,13 +257,13 @@ def _get_lib_by_instance(self, instance):
return lib
self._no_library_found(instance)

def get_runner(self, name):
def get_runner(self, name, recommend=True):
runner = self._get_runner(name)
if runner is None:
self._raise_no_keyword_found(name)
self._raise_no_keyword_found(name, recommend)
return runner

def _raise_no_keyword_found(self, name):
def _raise_no_keyword_found(self, name, recommend=True):
if name.strip(': ').upper() == 'FOR':
raise KeywordError(
f"Support for the old FOR loop syntax has been removed. "
Expand All @@ -276,10 +276,13 @@ def _raise_no_keyword_found(self, name):
"loop, remove escaping backslashes and end the loop with 'END'."
)
message = f"No keyword with name '{name}' found."
finder = KeywordRecommendationFinder(self.user_keywords,
self.libraries,
self.resources)
raise KeywordError(finder.recommend_similar_keywords(name, message))
if recommend:
finder = KeywordRecommendationFinder(self.user_keywords,
self.libraries,
self.resources)
raise KeywordError(finder.recommend_similar_keywords(name, message))
else:
raise KeywordError(message)

def _get_runner(self, name):
if not name:
Expand Down

0 comments on commit d9055f7

Please sign in to comment.