The functionality provided by this plugin has been merged into the pytest-ansible plugin.
Please switch to pytest-ansible for future updates.
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
If the molecule scenario does not contain information about the driver, the
test associated with it gets a no_driver
mark.
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 None
but you
can choose marks like skip
or xfail
.
The plugin adds --skip-no-git-change
option which an be used to skip tests
on unchanged roles according to git diff
result and thus can only be used
only when running pytest inside a git repository. It takes one argument and old
refspec used as a reference. For instance calling:
pytest --skip-no-git-change HEAD^
will result in molecule of roles that
weren't changed in the last commit being skipped.
If you need to skip or ignore a particular scenario, just add either xfail
or skip
to markers list inside its config file.
markers:
- xfail # broken scenario, pytest will run it but ignore the result
You can install "pytest-molecule" via pip from PyPI:
$ PIP_NO_BUILD_ISOLATION=false pip install pytest-molecule
PIP_NO_BUILD_ISOLATION
is needed only on ancient python distributions to
workaround pypa/pip#5229
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.