Skip to content

Commit 23566ea

Browse files
committed
Fix embedded args related regression
RF 7.3.1 (#5444) broke using Run Keyword and setup/teardown with embedded arguments that matched only after replacing variables. Fixes #5455.
1 parent f41e389 commit 23566ea

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

atest/robot/running/setup_and_teardown_using_embedded_arguments.robot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ Argument as non-string variable
3131
Should Be Equal ${tc[0].teardown.name} Object \${LIST}
3232
Should Be Equal ${tc.teardown.name} Object \${LIST}
3333

34+
Argument matching only after replacing variables
35+
${tc} = Check Test Case ${TESTNAME}
36+
Should Be Equal ${tc.setup.name} Embedded "arg"
37+
Should Be Equal ${tc[0].setup.name} Embedded "arg"
38+
Should Be Equal ${tc[0].teardown.name} Embedded "arg"
39+
Should Be Equal ${tc.teardown.name} Embedded "arg"
40+
3441
Exact match after replacing variables has higher precedence
3542
${tc} = Check Test Case ${TESTNAME}
3643
Should Be Equal ${tc.setup.name} Embedded not, exact match instead

atest/robot/standard_libraries/builtin/run_keyword.robot

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,17 @@ With library keyword accepting embedded arguments as variables containing object
6464
Check Run Keyword With Embedded Args ${tc[0]} Embedded "\${OBJECT}" in library Robot
6565
Check Run Keyword With Embedded Args ${tc[1]} Embedded object "\${OBJECT}" in library Robot
6666

67+
Embedded arguments matching only after replacing variables
68+
${tc} = Check Test Case ${TEST NAME}
69+
Check Run Keyword With Embedded Args ${tc[1]} Embedded "arg" arg
70+
Check Run Keyword With Embedded Args ${tc[2]} Embedded "arg" in library arg
71+
6772
Exact match after replacing variables has higher precedence than embedded arguments
6873
${tc} = Check Test Case ${TEST NAME}
69-
Check Run Keyword ${tc[1]} Embedded "not"
70-
Check Log Message ${tc[1][0][0][0]} Nothing embedded in this user keyword!
71-
Check Run Keyword ${tc[2]} embedded_args.Embedded "not" in library
72-
Check Log Message ${tc[2][0][0]} Nothing embedded in this library keyword!
74+
Check Run Keyword ${tc[1]} Embedded "not"
75+
Check Log Message ${tc[1][0][0][0]} Nothing embedded in this user keyword!
76+
Check Run Keyword ${tc[2]} embedded_args.Embedded "not" in library
77+
Check Log Message ${tc[2][0][0]} Nothing embedded in this library keyword!
7378

7479
Run Keyword In FOR Loop
7580
${tc} = Check Test Case ${TEST NAME}

atest/testdata/running/setup_and_teardown_using_embedded_arguments.robot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Suite Teardown Object ${LIST}
44

55
*** Variables ***
66
${ARG} arg
7+
${QUOTED} "${ARG}"
78
@{LIST} one ${2}
89
${NOT} not, exact match instead
910

@@ -26,6 +27,11 @@ Argument as non-string variable
2627
Keyword setup and teardown as non-string variable
2728
[Teardown] Object ${LIST}
2829

30+
Argument matching only after replacing variables
31+
[Setup] Embedded ${QUOTED}
32+
Keyword setup and teardown matching only after replacing variables
33+
[Teardown] Embedded ${QUOTED}
34+
2935
Exact match after replacing variables has higher precedence
3036
[Setup] Embedded ${NOT}
3137
Exact match after replacing variables has higher precedence
@@ -53,6 +59,11 @@ Keyword setup and teardown as non-string variable
5359
No Operation
5460
[Teardown] Object ${LIST}
5561

62+
Keyword setup and teardown matching only after replacing variables
63+
[Setup] Embedded ${QUOTED}
64+
No Operation
65+
[Teardown] Embedded ${QUOTED}
66+
5667
Embedded not, exact match instead
5768
No Operation
5869

atest/testdata/standard_libraries/builtin/run_keyword.robot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,18 @@ With library keyword accepting embedded arguments as variables containing object
7373
Run Keyword Embedded "${OBJECT}" in library
7474
Run Keyword Embedded object "${OBJECT}" in library
7575

76+
Embedded arguments matching only after replacing variables
77+
VAR ${arg} "arg"
78+
Run Keyword Embedded ${arg}
79+
Run Keyword Embedded ${arg} in library
80+
7681
Exact match after replacing variables has higher precedence than embedded arguments
7782
VAR ${not} not
7883
Run Keyword Embedded "${not}"
7984
Run Keyword Embedded "${{'NOT'}}" in library
85+
VAR ${not} "not"
86+
Run Keyword Embedded ${not}
87+
Run Keyword Embedded ${not} in library
8088

8189
Run Keyword In FOR Loop
8290
[Documentation] FAIL Expected failure in For Loop

src/robot/libraries/BuiltIn.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,11 +2184,14 @@ def _replace_variables_in_name(self, name, args, ctx):
21842184
# to 'Keyword.run', but then it would be better if 'Run Keyword' would support
21852185
# 'NONE' as a special value to not run anything similarly as setup/teardown.
21862186
replaced = ctx.variables.replace_scalar(name, ignore_errors=ctx.in_teardown)
2187-
runner = ctx.get_runner(replaced, recommend_on_failure=False)
2188-
if hasattr(runner, "embedded_args"):
2187+
if self._accepts_embedded(replaced, ctx) and self._accepts_embedded(name, ctx):
21892188
return name, args
21902189
return replaced, args
21912190

2191+
def _accepts_embedded(self, name, ctx):
2192+
runner = ctx.get_runner(name, recommend_on_failure=False)
2193+
return hasattr(runner, "embedded_args")
2194+
21922195
def _replace_variables_in_name_with_list_variable(self, name, args, ctx):
21932196
# TODO: This seems to be the only place where `replace_until` is used.
21942197
# That functionality should be removed from `replace_list` and implemented

src/robot/running/bodyrunner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ def _get_setup_teardown_runner(self, data, context):
108108
# BuiltIn.run_keyword has the same logic.
109109
runner = context.get_runner(name, recommend_on_failure=self._run)
110110
if hasattr(runner, "embedded_args") and name != data.name:
111-
runner = context.get_runner(data.name)
111+
candidate = context.get_runner(data.name)
112+
if hasattr(candidate, "embedded_args"):
113+
runner = candidate
112114
return runner
113115

114116

0 commit comments

Comments
 (0)