@@ -3024,28 +3024,35 @@ def evaluate(self, expression, modules=None, namespace=None):
3024
3024
namespace as a dictionary. Possible ``modules`` are added to this
3025
3025
namespace.
3026
3026
3027
- Starting from Robot Framework 3.2, modules used in the expression are
3028
- imported automatically. ``modules`` argument is still needed with
3029
- nested modules like ``rootmod.submod`` that are implemented so that
3030
- the root module does not automatically import sub modules. This is
3031
- illustrated by the ``selenium.webdriver`` example below.
3032
-
3033
3027
Variables used like ``${variable}`` are replaced in the expression
3034
3028
before evaluation. Variables are also available in the evaluation
3035
3029
namespace and can be accessed using the special ``$variable`` syntax
3036
3030
as explained in the `Evaluating expressions` section.
3037
3031
3032
+ Starting from Robot Framework 3.2, modules used in the expression are
3033
+ imported automatically. There are, however, two cases where they need to
3034
+ be explicitly specified using the ``modules`` argument:
3035
+
3036
+ - When nested modules like ``rootmod.submod`` are implemented so that
3037
+ the root module does not automatically import sub modules. This is
3038
+ illustrated by the ``selenium.webdriver`` example below.
3039
+
3040
+ - When using a module in the expression part of a list comprehension.
3041
+ This is illustrated by the ``json`` example below.
3042
+
3038
3043
Examples (expecting ``${result}`` is number 3.14):
3039
3044
| ${status} = | Evaluate | 0 < ${result} < 10 | # Would also work with string '3.14' |
3040
3045
| ${status} = | Evaluate | 0 < $result < 10 | # Using variable itself, not string representation |
3041
3046
| ${random} = | Evaluate | random.randint(0, sys.maxsize) |
3042
3047
| ${options} = | Evaluate | selenium.webdriver.ChromeOptions() | modules=selenium.webdriver |
3048
+ | ${items} = | Evaluate | [json.loads(item) for item in ('1', '"b"')] | modules=json |
3043
3049
| ${ns} = | Create Dictionary | x=${4} | y=${2} |
3044
3050
| ${result} = | Evaluate | x*10 + y | namespace=${ns} |
3045
3051
=>
3046
3052
| ${status} = True
3047
3053
| ${random} = <random integer>
3048
3054
| ${options} = ChromeOptions instance
3055
+ | ${items} = [1, 'b']
3049
3056
| ${result} = 42
3050
3057
3051
3058
*NOTE*: Prior to Robot Framework 3.2 using ``modules=rootmod.submod``
@@ -3357,10 +3364,10 @@ class BuiltIn(_Verify, _Converter, _Variables, _RunKeyword, _Control, _Misc):
3357
3364
3358
3365
`Evaluate` also allows configuring the execution namespace with a custom
3359
3366
namespace and with custom modules to be imported. The latter functionality
3360
- is useful when using nested modules like ``rootmod.submod`` that are
3361
- implemented so that the root module does not automatically import sub
3362
- modules. Otherwise the automatic module import mechanism described earlier
3363
- is enough to get the needed modules imported .
3367
+ is useful in special cases where the automatic module import does not work
3368
+ such as when using nested modules like ``rootmod.submod`` or list
3369
+ comprehensions. See the documentation of the `Evaluate` keyword for mode
3370
+ details .
3364
3371
3365
3372
*NOTE:* Automatic module import is a new feature in Robot Framework 3.2.
3366
3373
Earlier modules needed to be explicitly taken into use when using the
0 commit comments