Skip to content

Commit 764219f

Browse files
committed
Fix handling mutable IF conditions
Fixes #5645.
1 parent 8980648 commit 764219f

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

atest/robot/running/if/if_else.robot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ If failing in keyword
3939
If failing in else keyword
4040
Check Test Case ${TESTNAME}
4141

42+
Mutable condition
43+
${tc} = Check Test Case ${TESTNAME}
44+
Check Log Message ${tc[1, 0, 1, 0]} Should be executed!
45+
4246
Expression evaluation time is included in elapsed time
4347
${tc} = Check Test Case ${TESTNAME}
4448
Elapsed Time Should Be Valid ${tc[0].elapsed_time} minimum=0.2

atest/testdata/running/if/if_else.robot

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ If failing in else keyword
6666
[Documentation] FAIL expected
6767
Failing else keyword
6868

69+
Mutable condition
70+
VAR @{condition} bar baz
71+
IF $condition
72+
Call Method ${condition} clear
73+
Log Should be executed!
74+
ELSE
75+
Fail Should not be executed!
76+
END
77+
IF $condition
78+
Fail Should not be executed!
79+
END
80+
6981
Expression evaluation time is included in elapsed time
7082
IF ${{time.sleep(0.1)}}
7183
Fail Not run

src/robot/running/bodyrunner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ def run(self, data, result):
597597
):
598598
self._run = False
599599
except ExecutionStatus as err:
600-
error = err
601600
self._run = False
601+
error = err
602602
if error:
603603
raise error
604604

@@ -630,8 +630,8 @@ def _run_if_branch(self, data, result, recursive_dry_run=False, syntax_error=Non
630630
try:
631631
run_branch = self._should_run_branch(data, context, recursive_dry_run)
632632
except DataError as err:
633-
error = err
634633
run_branch = False
634+
error = err
635635
with StatusReporter(data, result, context, run_branch):
636636
runner = BodyRunner(context, run_branch, self._templated)
637637
if not recursive_dry_run:
@@ -648,14 +648,16 @@ def _should_run_branch(self, data, context, recursive_dry_run=False):
648648
if data.condition is None:
649649
return True
650650
try:
651-
return evaluate_expression(
651+
condition = evaluate_expression(
652652
data.condition,
653653
context.variables.current,
654654
resolve_variables=True,
655655
)
656656
except Exception:
657657
msg = get_error_message()
658658
raise DataError(f"Invalid {data.type} condition: {msg}")
659+
else:
660+
return bool(condition)
659661

660662

661663
class TryRunner:

0 commit comments

Comments
 (0)