Skip to main content

A CLI tool to render and execute Robot Framework tests using Jinja templating.

Project description

Tests Python Support

iac-test

A CLI tool to render and execute Robot Framework tests using Jinja templating. Combining Robot's language agnostic syntax with the flexibility of Jinja templating allows dynamically rendering a set of test suites from the desired infrastructure state expressed in YAML syntax.

$ iac-test -h
Usage: iac-test [OPTIONS]

  A CLI tool to render and execute Robot Framework tests using Jinja
  templating.

Options:
  --version                  Show the version and exit.
  -v, --verbosity LVL        Either CRITICAL, ERROR, WARNING, INFO or DEBUG
  -d, --data PATH            Path to data YAML files.  [required]
  -t, --templates DIRECTORY  Path to test templates.  [required]
  -f, --filters DIRECTORY    Path to Jinja filters.
  -o, --output DIRECTORY     Path to output directory.  [required]
  --render-only              Only render tests without executing.
  -h, --help                 Show this message and exit.

All data from the YAML files (--data option) will first be combined into a single data structure which is then provided as input to the templating process. Each template in the --templates path will then be rendered and written to the --output path. If the --templates path has subfolders, the folder structure will be retained when rendering the templates.

After all templates have been rendered Pabot will execute all test suites in parallel and create a test report in the --output path. The --skiponfailure non-critical argument will be used by default, meaning all failed tests with a non-critical tag will show up as "skipped" instead of "failed" in the final test report.

Example

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 iac-test with the following parameters:

iac-test --data ./data --templates ./templates --output ./tests

The following rendered Robot test suite can be found in the ./tests 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:

$ tree -L 1 tests
tests
├── log.html
├── output.xml
├── pabot_results
├── report.html
└── test1.robot

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"

Rendering Directives

A special rendering directive exists to render a single test suite per (YAML) list item. The directive can be added to the Robot template as a Jinja comment following this syntax:

{# iterate_list <YAML_PATH_TO_LIST> <LIST_ITEM_ID> <JINJA_VARIABLE_NAME> #}

After running iac-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
tests
├── ABC
│   └── test1.robot
└── DEF
    └── test1.robot

Select Test Cases By Tag

It is possible to include and exclude test cases by tag names with the --include and --exclude CLI options. These options are directly passed to the Pabot/Robot executor and are documented here.

Installation

Python 3.6+ is required to install iac-test. Don't have Python 3.6 or later? See Python 3 Installation & Setup Guide.

iac-test can be installed in a virtual environment using pip:

pip install iac-test

The following Robot libraries are installed with iac-test:

Any other libraries can of course be added via pip.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iac-test-0.1.1.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iac_test-0.1.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file iac-test-0.1.1.tar.gz.

File metadata

  • Download URL: iac-test-0.1.1.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.8.10 Linux/5.15.0-1019-azure

File hashes

Hashes for iac-test-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a1a689eecaa9e88e223e6f3bea17111ca90f601c07c84219ce0efc4ebc29eb95
MD5 6affac5e63d1db08c7267b50691e40fd
BLAKE2b-256 105d0bc86cb2ffb95bda016eb266c548f9d828ca6d425ebc7df977860ebfac95

See more details on using hashes here.

File details

Details for the file iac_test-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: iac_test-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.8.10 Linux/5.15.0-1019-azure

File hashes

Hashes for iac_test-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f411a209e7353682bd3bf19dc828de378889616808c90a8f1c956698a76fb02
MD5 725952a5facb24771ab0c0fb3d827053
BLAKE2b-256 65c7454c7dbbdc77eeb56ca1e5acb4536b65ee1dcfce28da70c068f85329a207

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page