Skip to content

Commit 4b85e50

Browse files
committed
Fix keyword teardown w/ non-existing variable in dry-run
Fixes robotframework#3229
1 parent 7fc920d commit 4b85e50

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

atest/robot/cli/dryrun/dryrun.robot

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ Setup/teardown with non-existing variable is ignored
6060

6161
Setup/teardown with existing variable is resolved and executed
6262
${tc} = Check Test Case ${TESTNAME}
63-
Should Be Equal ${tc.setup.name} BuiltIn.No Operation
64-
Should Be Equal ${tc.teardown.name} Teardown
65-
${args} = Create List \${nonex arg}
66-
Lists Should Be Equal ${tc.teardown.args} ${args}
67-
Should Be Equal ${tc.teardown.keywords[0].name} BuiltIn.Log
63+
Check Keyword Data ${tc.setup} BuiltIn.No Operation status=NOT_RUN
64+
Check Keyword Data ${tc.teardown} Teardown args=\${nonex arg}
65+
Check Keyword Data ${tc.teardown.keywords[0]} BuiltIn.Log args=\${arg} status=NOT_RUN
6866

6967
User keyword return value
7068
Check Test Case ${TESTNAME}
@@ -80,6 +78,14 @@ Keyword Teardown
8078
Should have correct number of keywords ${tc} 2
8179
Should Be Equal ${tc.kws[0].kws[1].name} Does not exist
8280

81+
Keyword teardown with non-existing variable is ignored
82+
Check Test Case ${TESTNAME}
83+
84+
Keyword teardown with existing variable is resolved and executed
85+
${tc}= Check Test Case ${TESTNAME}
86+
Check Keyword Data ${tc.kws[0].kws[-1]} Teardown args=\${I DO NOT EXIST}
87+
Check Keyword Data ${tc.kws[0].kws[-1].kws[0]} BuiltIn.Log args=\${arg} status=NOT_RUN
88+
8389
For Loops
8490
${tc}= Check Test Case ${TESTNAME}
8591
Should have correct number of keywords ${tc} 4

atest/testdata/cli/dryrun/dryrun.robot

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Suite Setup ${SUITE SETUP}
1313
# Library keywords get NOT_RUN status. That should be OK teardown status.
1414
Suite Teardown No Operation
1515

16-
1716
*** Variables ***
1817
${SETUP} No Operation
1918
${TEARDOWN} Teardown
@@ -89,6 +88,14 @@ Keyword Teardown
8988
Keyword with Teardown
9089
This is validated
9190

91+
Keyword teardown with non-existing variable is ignored
92+
Keyword with teardown with non-existing variable
93+
This is validated
94+
95+
Keyword teardown with existing variable is resolved and executed
96+
Keyword with teardown with existing variable
97+
This is validated
98+
9299
For Loops
93100
[Documentation] FAIL Keyword 'resource.Anarchy in the UK' expected 3 arguments, got 2.
94101
FOR ${i} IN RANGE 10
@@ -137,6 +144,14 @@ Keyword with Teardown
137144
No Operation
138145
[Teardown] Does not exist
139146

147+
Keyword with teardown with non-existing variable
148+
No Operation
149+
[Teardown] ${I DO NOT EXIST}
150+
151+
Keyword with teardown with existing variable
152+
No Operation
153+
[Teardown] ${TEARDOWN} ${I DO NOT EXIST}
154+
140155
Invalid Syntax UK
141156
[Arguments] ${arg
142157
No Operation

src/robot/running/userkeywordrunner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ def _run_teardown(self, context):
192192
try:
193193
name = context.variables.replace_string(self._handler.teardown.name)
194194
except DataError as err:
195+
if context.dry_run:
196+
return None
195197
return ExecutionFailed(err.message, syntax=True)
196198
if name.upper() in ('', 'NONE'):
197199
return None

0 commit comments

Comments
 (0)