Skip to content

Reference

This reference documents how nac-test renders and executes Robot Framework templates. The Test Case Guide explains how to use these features.

File typeHandling
.robot, .resource, .j2Rendered with Jinja and written to <output>/robot_results/ with the same relative path
Any other file (e.g. .py keyword libraries)Copied unchanged to <output>/robot_results/ with the same relative path

The rendered .robot files are executed. A rendered suite without test cases doesn’t produce any test results.

VariableDescription
Data model root keys (apic, sdwan, nxos, iosxe, defaults, …)The merged data model from all --data files
robot_include_tagsList of the --include patterns of the current run (empty list if none)
robot_exclude_tagsList of the --exclude patterns of the current run (empty list if none)
Directive variableThe item identifier set by a rendering directive, e.g. item[2] or child_name
SettingEffect
Strict chainable undefinedAccessing 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_blocksThe first newline after a block tag is removed
lstrip_blocksWhitespace before a block tag on the same line is removed
Blank line cleanupAfter rendering, blank lines are removed unless the following line starts in the first column (keeping blank lines between test cases)
Filters and testsJinja built-ins, plus the custom filters and tests loaded from --filters and --tests

The following example is used by the sections below. data.yaml located in ./data folder:

---
root:
children:
- name: ABC
param: value
- name: DEF
param: value

test1.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:

Terminal window
nac-test --data ./data --templates ./templates --output ./tests

The 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 value

As well as the test results and reports:

Terminal window
$ tree -L 2 tests
tests
├── 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.xml

See Results and Reports for a description of the output directory.

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.

ParameterDescription
<YAML_PATH_TO_LIST>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_NAME>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.

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:

Terminal window
$ tree -L 2 tests/robot_results
tests/robot_results
├── ABC
│ └── test1.robot
└── DEF
└── test1.robot

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:

Terminal window
$ tree -L 2 tests/robot_results
tests/robot_results
└── test1
├── ABC.robot
└── DEF.robot

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: value

After 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:

Terminal window
$ tree -L 2 tests/robot_results
tests/robot_results
├── ABC
│ ├── test1_001.robot
│ └── test1_002.robot
└── DEF
└── test1_001.robot

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 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 == data2

Use it in a template as {% if value is test1(other) %}.

nac-test installs the following Robot Framework libraries, in addition to the Robot Framework standard libraries (BuiltIn, Collections, String, OperatingSystem, DateTime, XML, …):

LibraryImportTypical use
robotframework-requestsLibrary RequestsLibraryHTTP sessions and requests (Create Session, GET On Session, POST On Session)
robotframework-jmespathLibrary JMESPathLibraryJMESPath queries on JSON (JSON Search, JSON Search String, JSON Search List)
robotframework-jsonlibraryLibrary JSONLibraryJSONPath queries (Get Value From Json)
robotframework-pabotLibrary pabot.PabotLibSharing 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.

nac-test runs the rendered suites with Pabot and the following Robot options:

OptionValue
--outputdir<output>/robot_results
--skiponfailurenon-critical — failed tests tagged non-critical are reported as skipped
--xunitxunit.xml
--include / --excludeFrom the nac-test --include / --exclude options
--dryrunWith the nac-test --dry-run option
--loglevelDEBUG when nac-test runs with --loglevel DEBUG, unless overridden

The number of parallel Pabot processes is set with --processes (default: max(2, cpu count)).

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.

Terminal window
nac-test -d data/ -t templates/ -o results/ --variable ENV:lab --loglevel TRACE

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 True

Note: 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).