Skip to main content

A Pytest plugin that builds and creates docker containers

Project description


A Pytest plugin that makes it easy to write integration tests for salt


This `Pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template.


You can install "pytest-salt-containers" via `pip`_ from `PyPI`_::

$ pip install pytest-salt-containers


How to write tests and how they work

Writing a "" test

For this we need a salt master and a minion.
We can do that by creating a new file in the `tests` folder:

.. compound::


def test_ping_minion(master, minion):

This uses `master` and `minion` fixtures defined in `tests/`.

_Note: The fixtures defined in `` (or in the current file) are automatically discovered by `py.test`_

The fixtures rely on [fatory-boy]( factories defined in `tests/`.
The factories take care of running `sast-master` and `salt-minion` in separate docker containers (it is also possible to run them in the same container).

With this, we have a running salt-master and a salt-minion.

To make master accept minion, I have created a convenient fixture called `minion_key_accepted`
Let's modify the test above to use it.

.. compound::


def test_ping_minion(master, minion, minion_key_accepted):

To run `salt <minion-id>` on master and assert minion replied, do this:

.. compound::


def test_ping_minion(master, minion, minion_key_accepted):
assert master.salt(minion['id'], "")[minion['id']] is True

This might fail sometimes because the command might be run before .
In order to avoid that, I have created a `retry` helper that raises an exception if the command was not successful within `config.TIME_LIMIT`. So we need to change the test like this:

.. compound::


from utils import retry

def test_ping_minion(master, minion, minion_key_accepted):

def ping():
return master.salt(minion['id'], "")[minion['id']]

assert retry(ping)

Contributions are very welcome. Tests can be run with `tox`_, please ensure
the coverage at least stays the same before you submit a pull request.


Distributed under the terms of the `MIT`_ license, "pytest-salt-containers" is free and open source software


If you encounter any problems, please `file an issue`_ along with a detailed description.

.. _`Cookiecutter`:
.. _`@hackebrot`:
.. _`MIT`:
.. _`BSD-3`:
.. _`GNU GPL v3.0`:
.. _`Apache Software License 2.0`:
.. _`cookiecutter-pytest-plugin`:
.. _`file an issue`:
.. _`pytest`:
.. _`tox`:
.. _`pip`:
.. _`PyPI`:

Download files

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

Source Distribution

pytest-salt-containers-0.2.9.tar.gz (7.4 kB view hashes)

Uploaded source

Supported by

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