Skip to main content

PyTest Molecule Plugin :: discover and run molecule tests

Project description

PyPI version Python versions See Build Status on Travis CI Python Black Code Style

PyTest Molecule Plugin :: auto detects and runs molecule tests

This plugin enables pytest discovery of all molecule.yml files inside the codebase and runs them as pytest tests.

Once you install pytest-molecule you should be able to just run pytest in order to run molecule on all roles and scenarios.

Optionally you can define MOLECULE_OPTS for passing extra parameters to each molecule call.

Discovered tests do have molecule driver and platforms added as markers, so you can selectively limit which test types to run:

# Lists all tests that uses docker
$ pytest --collect-only -m docker

# Runs scenarios with platform named centos7 and delegated driver:
$ pytest -m delegated -m centos7

Please note that at this moment molecule will run the entire scenario if the markers are platforms, this is not yet a way to limit which platforms are executed inside a specific scenario.

All tests are added the molecule marker.

This plugin also adds a new pytest option named --molecule-unavailable-driver=skip which can be used to tell it what to do when molecule drivers are not loading. Current default is skip but you can choose other marks like xfail or empty string if you want to disable this functionality.

Current implementation of this feature validates only docker and delegated drivers. Due to the potential destructive nature of delegated driver, scenarios running it will run only if Ansible detects one of the following variables as defined: zuul, use_for_testing.


You can install “pytest-molecule” via pip from PyPI:

.. code-block:: shell
$ PIP_NO_BUILD_ISOLATION=false pip install pytest-molecule

PIP_NO_BUILD_ISOLATION is needed only on ancient python distributions to workaround


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-molecule” is free and open source software


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

Download files

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

Files for pytest-molecule, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size pytest_molecule-1.1.0-py2.py3-none-any.whl (6.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pytest-molecule-1.1.0.tar.gz (15.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page