Skip to main content
PyPI version Python versions See Build Status on Zuul 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

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.

Using xfail and skip markers

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

Installation

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 https://github.com/pypa/pip/issues/5229

Contributing

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.

License

Distributed under the terms of the MIT license, “pytest-molecule” is free and open source software

Issues

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

Release files for pytest-molecule 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-molecule 2.0.0
File Size Uploaded
pytest-molecule-2.0.0.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-molecule 2.0.0
File Interpreter ABI Platform
pytest_molecule-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.2 kB

Release files / pytest-molecule-2.0.0.tar.gz

Download URL pytest-molecule-2.0.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e8ab7d15b02e67c6e08fd50d1c56881e5e1ad6d43bbe2d2f86babc2b60a5d8ba
BLAKE2b-256 checksum
How to use checksums
2e63086152bac597a6fcc549fba537adcf6865b6ecb98c3274e277b33a157d53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

Release files / pytest_molecule-2.0.0-py3-none-any.whl

Download URL pytest_molecule-2.0.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57109456cf0a2f382bead3377b7ccb1ed61760ee44f1b1bacf038affdb0be000
BLAKE2b-256 checksum
How to use checksums
22f2b972fb2e6d0e1a560aaabb7d13fad59508b4a340cd5ad5225c0e252b7a23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page