Reference
This reference documents how nac-test renders and executes Robot Framework templates. The Test Case Guide explains how to use these features.
Template Files
Section titled “Template Files”| File type | Handling |
|---|---|
.robot, .resource, .j2 | Rendered with Jinja and written to <output>/ with the same relative path |
Any other file (e.g. .py keyword libraries) | Copied unchanged to <output>/ with the same relative path |
The rendered .robot files are executed. A rendered suite without test cases doesn’t produce any test results.
Template Context
Section titled “Template Context”| Variable | Description |
|---|---|
Data model root keys (apic, sdwan, nxos, iosxe, defaults, …) | The merged data model from all --data files |
robot_ | List of the --include patterns of the current run (empty list if none) |
robot_ | List of the --exclude patterns of the current run (empty list if none) |
| Directive variable | The item identifier set by a rendering directive, e.g. item[2] or child_name |
Jinja Environment
Section titled “Jinja Environment”| Setting | Effect |
|---|---|
| Strict chainable undefined | Accessing missing keys in a chain (a.b.c) is allowed, but printing, iterating, comparing or testing the truthiness of an undefined value raises an error. Use | default(...) or is defined. |
trim_blocks | The first newline after a block tag is removed |
lstrip_blocks | Whitespace before a block tag on the same line is removed |
| Blank line cleanup | After rendering, blank lines are removed unless the following line starts in the first column (keeping blank lines between test cases) |
| Filters and tests | Jinja built-ins, plus the custom filters and tests loaded from --filters and --tests |
Example
Section titled “Example”The following example is used by the sections below. data.yaml located in ./data folder:
---root: children: - name: ABC param: value - name: DEF param: valuetest1.robot located in ./templates folder:
*** Settings ***Documentation Test1
*** Test Cases ***{% for child in root.children | default([]) %}
Test {{ child.name }} Should Be Equal {{ child.param }} value{% endfor %}After running nac-test with the following parameters:
nac-test --data ./data --templates ./templates --output ./testsThe following rendered Robot test suite can be found in the ./tests/robot_results folder:
*** Settings ***Documentation Test1
*** Test Cases ***
Test ABC Should Be Equal value value
Test DEF Should Be Equal value valueAs well as the test results and reports:
$ tree -L 2 teststests├── combined_summary.html├── robot_results/│ ├── log.html│ ├── output.xml│ ├── report.html│ ├── xunit.xml│ └── test1.robot├── log.html -> robot_results/log.html├── output.xml -> robot_results/output.xml├── report.html -> robot_results/report.html└── xunit.xmlSee Results and Reports for a description of the output directory.
Rendering Directives
Section titled “Rendering Directives”Rendering directives render a template once per item of a (YAML) list. A directive is a Jinja comment anywhere in the template, with its parameters separated by single spaces.
| Parameter | Description |
|---|---|
<YAML_ | Dot-separated path to the list in the data model, e.g. apic.tenants |
<LIST_ITEM_ID> | Attribute of each list item used as identifier, e.g. name. Items without this attribute are skipped. |
<JINJA_ | Variable that receives the identifier (as a string) when rendering. With var[n], a list named var is passed with the identifier at index n. |
iterate_list
Section titled “iterate_list”Renders one test suite per list item, each in a folder named after the item:
{# iterate_list <YAML_PATH_TO_LIST> <LIST_ITEM_ID> <JINJA_VARIABLE_NAME> #}After running nac-test with the data from the previous example and the following template:
{# iterate_list root.children name child_name #}*** Settings ***Documentation Test1
*** Test Cases ***{% for child in root.children | default([]) %}{% if child.name == child_name %}
Test {{ child.name }} Should Be Equal {{ child.param }} value{% endif %}{% endfor %}The following test suites will be rendered:
$ tree -L 2 tests/robot_resultstests/robot_results├── ABC│ └── test1.robot└── DEF └── test1.robotiterate_list_folder
Section titled “iterate_list_folder”Puts the test suites in a common folder named after the template, with the item as filename:
{# iterate_list_folder <YAML_PATH_TO_LIST> <LIST_ITEM_ID> <JINJA_VARIABLE_NAME> #}The following test suites will be rendered:
$ tree -L 2 tests/robot_resultstests/robot_results└── test1 ├── ABC.robot └── DEF.robotiterate_list_chunked
Section titled “iterate_list_chunked”Renders a single test suite per (YAML) list item in chunks, which is useful for handling large datasets by splitting them across multiple suites. This is a variant of iterate_list that still creates separate folders.
Note: This directive is experimental and may change in future versions. It is not subject to semantic versioning guarantees.
{# iterate_list_chunked <YAML_PATH_TO_LIST> <LIST_ITEM_ID> <JINJA_VARIABLE_NAME> <OBJECT_PATH> <CHUNK_SIZE> #}All objects under <OBJECT_PATH> (relative to the list item) are counted, and if their number is greater than <CHUNK_SIZE>, the item is split into multiple test suites, each rendered with only its chunk of objects.
Consider the following example:
---root: children: - name: ABC param: value nested_children: - name: Child1 param: value - name: Child2 param: value - name: Child3 param: value - name: DEF param: value nested_children: - name: Child1 param: valueAfter running nac-test with this data and the following template:
{# iterate_list_chunked root.children name child_name nested_children 2 #}*** Settings ***Documentation Test1
*** Test Cases ***{% for child in root.children | default([]) %}{% if child.name == child_name %}
Test {{ child.name }} Should Be Equal {{ child.param }} value
{% for nested_child in child.nested_children | default([]) %}
Test {{ child.name }} Child {{ nested_child.name }} Should Be Equal {{ nested_child.param }} value{% endfor %}
{% endif %}{% endfor %}Objects from the nested_children path are counted, and since their number is greater than the chunk size (2) for ABC, it is split into multiple test suites with suffix _001, _002, etc. The following test suites will be rendered:
$ tree -L 2 tests/robot_resultstests/robot_results├── ABC│ ├── test1_001.robot│ └── test1_002.robot└── DEF └── test1_001.robotCustom Jinja Filters
Section titled “Custom Jinja Filters”Custom Jinja filters can be used by providing a set of Python classes where each filter is implemented as a separate Filter class in a .py file located in the --filters path. The class must have a single attribute named name, the filter name, and a classmethod() named filter which has one or more arguments. A sample filter can be found below.
class Filter: name = "filter1"
@classmethod def filter(cls, data): return str(data) + "_filtered"Use it in a template as {{ value | filter1 }}. Additional filter arguments are passed after the value: {{ value | filter1(arg) }} calls filter(data, arg).
Custom Jinja Tests
Section titled “Custom Jinja Tests”Custom Jinja tests can be used by providing a set of Python classes where each test is implemented as a separate Test class in a .py file located in the --tests path. The class must have a single attribute named name, the test name, and a classmethod() named test which has one or more arguments. A sample test can be found below.
class Test: name = "test1"
@classmethod def test(cls, data1, data2): return data1 == data2Use it in a template as {% if value is test1(other) %}.
Bundled Libraries
Section titled “Bundled Libraries”nac-test installs the following Robot Framework libraries, in addition to the Robot Framework standard libraries (BuiltIn, Collections, String, OperatingSystem, DateTime, XML, …):
| Library | Import | Typical use |
|---|---|---|
| robotframework-requests | Library RequestsLibrary | HTTP sessions and requests (Create Session, GET On Session, POST On Session) |
| robotframework-jmespath | Library JMESPathLibrary | JMESPath queries on JSON (JSON Search, JSON Search String, JSON Search List) |
| robotframework-jsonlibrary | Library JSONLibrary | JSONPath queries (Get Value From Json) |
| robotframework-pabot | Library pabot.PabotLib | Sharing values and locks across parallel processes (Run Only Once, Set Parallel Value For Key, Get Parallel Value For Key, Acquire Lock, Run On Last Process) |
JSON Search String returns the first match as a string, or an empty string if nothing matches. JSON Search List returns all matches as a list, or an empty list.
Robot Execution
Section titled “Robot Execution”nac-test runs the rendered suites with Pabot and the following Robot options:
| Option | Value |
|---|---|
--outputdir | <output>/ |
--skiponfailure | non-critical — failed tests tagged non-critical are reported as skipped |
--xunit | xunit.xml |
--include / --exclude | From the nac-test --include / --exclude options |
--dryrun | With the nac-test --dry-run option |
--loglevel | DEBUG when nac-test runs with --loglevel DEBUG, unless overridden |
The number of parallel Pabot processes is set with --processes (default: max(2, cpu count)).
Robot Options
Section titled “Robot Options”Additional Robot Framework options can be passed at the end of the nac-test command (e.g., --variable, --listener, --loglevel). They are appended to the Pabot invocation. Pabot-specific options and test files/directories are not supported and result in an error.
nac-test -d data/ -t templates/ -o results/ --variable ENV:lab --loglevel TRACETest Concurrency
Section titled “Test Concurrency”By default, nac-test (via pabot) executes test suites (i.e., each robot file) in parallel.
However, suite-level parallelization may be inefficient for test suites containing multiple long-running test cases (e.g., >10 seconds each). If your test cases are independent and can run concurrently, you can enable test-level parallelization by adding the following metadata to the suite’s settings:
*** Settings ***Metadata Test Concurrency TrueNote: This approach benefits only long-running tests. For short tests, the scheduling overhead and log collection may offset any performance gains.
Tip: The Test Concurrency metadata is case-insensitive (test concurrency, TEST CONCURRENCY, etc.).
Implementation: nac-test checks the rendered robot files for the Metadata setting and instructs pabot to run each test within the respective suite in parallel (using pabot’s --testlevelsplit --ordering ordering.txt arguments). You can inspect the ordering.txt file in the robot_results/ directory.
This behaviour can be disabled by setting the environment variable NAC_TEST_DISABLE_TESTLEVELSPLIT=true (as of nac-test 2.0; previously named NO_TESTLEVELSPLIT).