Skip to main content

PyTest Molecule Plugin :: discover and run molecule tests

Project description

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.

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.

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.

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

pytest_molecule_JC-2.0.0.post2.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

pytest_molecule_JC-2.0.0.post2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_molecule_JC-2.0.0.post2.tar.gz.

File metadata

  • Download URL: pytest_molecule_JC-2.0.0.post2.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8

File hashes

Hashes for pytest_molecule_JC-2.0.0.post2.tar.gz
Algorithm Hash digest
SHA256 0a834ecb66be677781574591a406c6429a2616cee4c34b273deff6e1863c3172
MD5 07670495985b6e75d8991f81a160fc52
BLAKE2b-256 48be273b8f7d246dfc9103994b73c63399d674cc3929973328cfc826277feaa9

See more details on using hashes here.

File details

Details for the file pytest_molecule_JC-2.0.0.post2-py3-none-any.whl.

File metadata

  • Download URL: pytest_molecule_JC-2.0.0.post2-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.11 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.8

File hashes

Hashes for pytest_molecule_JC-2.0.0.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 ffd3c07411c82f2b038b355ba6a02df7373db9e1b3be0bee947827f28c1e226b
MD5 2a5085b98e4bce4628f55091e45d2a24
BLAKE2b-256 2200b60bc34f39e0cd5a9f0daba7eba82dc3326a25c04550b1cf8c299c274779

See more details on using hashes here.

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