Skip to content

Commit e657d03

Browse files
committed
Support '.yml' extension w/ YAML variable files. Fixes robotframework#3195.
1 parent ea54583 commit e657d03

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

atest/robot/variables/yaml_variable_file.robot

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*** Settings ***
2-
Suite Setup Run Tests --variablefile ${VARDIR}/cli.yaml --pythonpath ${VARDIR} variables/yaml_variable_file.robot
2+
Suite Setup Run Tests --variablefile ${VARDIR}/cli.yaml -V ${VARDIR}/cli.YML --pythonpath ${VARDIR}
3+
... variables/yaml_variable_file.robot
34
Force Tags require-yaml
45
Resource atest_resource.robot
56

@@ -10,6 +11,9 @@ ${VARDIR} ${DATADIR}/../testresources/res_and_var_files
1011
Valid YAML file
1112
Check Test Case ${TESTNAME}
1213

14+
Valid YML file
15+
Check Test Case ${TESTNAME}
16+
1317
Non-ASCII strings
1418
[Tags] no-ipy
1519
Check Test Case ${TESTNAME}

atest/testdata/variables/valid.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
string in yml: Hello, YML!
2+
integer in yml: 42
3+
float in yml: 3.14
4+
list in yml:
5+
- one
6+
- 2
7+
dict in yml:
8+
a: '1'
9+
b: 2
10+
3: [one, 2]
11+
key with spaces: value with spaces

atest/testdata/variables/yaml_variable_file.robot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*** Settings ***
22
Variables valid.yaml
3+
Variables valid.yml
34
Variables pythonpath.yaml
45
Variables ./invalid.YAML
56
Variables ..${/}variables${/}non_dict.yaml
@@ -20,6 +21,13 @@ Valid YAML file
2021
${LIST} ${EXPECTED LIST}
2122
${DICT} ${EXPECTED DICT}
2223

24+
Valid YML file
25+
${STRING IN YML} Hello, YML!
26+
${INTEGER IN YML} ${42}
27+
${FLOAT IN YML} ${3.14}
28+
${LIST IN YML} ${EXPECTED LIST}
29+
${DICT IN YML} ${EXPECTED DICT}
30+
2331
Non-ASCII strings
2432
${NON} äscii
2533
${NÖN} äscii
@@ -40,3 +48,4 @@ Import Variables keyword
4048

4149
YAML file from CLI
4250
${YAML FILE FROM CLI} woot!
51+
${YML FILE FROM CLI} kewl!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yml file from cli: kewl!

doc/userguide/src/CreatingTestData/ResourceAndVariableFiles.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,14 @@ The following example demonstrates a simple YAML file:
576576
pip_ installed, you can install it simply by running
577577
`pip install pyyaml`.
578578

579-
YAML support is new in Robot Framework 2.9. Starting from
580-
version 2.9.2, the `standalone JAR distribution`_ has
581-
PyYAML included by default.
579+
YAML variable files must have either :file:`.yaml` or :file:`.yml`
580+
extension. Support for the :file:`.yml` extension is new in
581+
Robot Framework 3.2.
582582

583583
YAML variable files can be used exactly like normal variable files
584584
from the command line using :option:`--variablefile` option, in the settings
585585
table using :setting:`Variables` setting, and dynamically using the
586-
:name:`Import Variables` keyword. The only thing to remember is that paths to
587-
YAML files must always end with :file:`.yaml` extension.
586+
:name:`Import Variables` keyword.
588587

589588
If the above YAML file is imported, it will create exactly the same
590589
variables as the following variable table:
@@ -609,5 +608,5 @@ Most importantly, values of these dictionaries are accessible as attributes
609608
like `${DICT.one}`, assuming their names are valid as Python attribute names.
610609
If the name contains spaces or is otherwise not a valid attribute name, it is
611610
always possible to access dictionary values using syntax like
612-
`&{DICT}[with spaces]` syntax. The created dictionaries are also ordered, but
611+
`${DICT}[with spaces]` syntax. The created dictionaries are also ordered, but
613612
unfortunately the original source order of in the YAML file is not preserved.

src/robot/variables/filesetter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _import_if_needed(self, path_or_variables, args=None):
4141
return path_or_variables
4242
LOGGER.info("Importing variable file '%s' with args %s"
4343
% (path_or_variables, args))
44-
if path_or_variables.lower().endswith('.yaml'):
44+
if path_or_variables.lower().endswith(('.yaml', '.yml')):
4545
importer = YamlImporter()
4646
else:
4747
importer = PythonImporter()

0 commit comments

Comments
 (0)