Skip to main content

A py.test plugin providing fixtures to simplify inmanta modules testing.

Project description

pytest-inmanta

A pytest plugin to test inmanta modules

Installation

pip install pytest-inmanta

Usage

This plugin provides a test fixture that can compile, export and deploy code without running an actual inmanta server.

def test_compile(project):
    """
        Test compiling a simple model that uses std
    """
    project.compile("""
host = std::Host(name="server", os=std::linux)
file = std::ConfigFile(host=host, path="/tmp/test", content="1234")
        """)

The fixture also provides access to the model internals

    assert len(project.get_all_instances("std::Host")) == 1
    assert project.get_all_instances("std::Host")[0].name == "myhost"

To the exported resources

    f = project.get_resource("std::ConfigFile")
    assert f.permissions == 644

To compiler output and mock filesystem

def test_template(project):
    """
        Test the evaluation of a template
    """
    project.add_mock_file("templates", "test.tmpl", "{{ value }}")
    project.compile("""import unittest
value = "1234"
std::print(std::template("unittest/test.tmpl"))
    """)

    assert project.get_stdout() == "1234\n"

And allows deploy

    project.deploy_resource("std::ConfigFile")

And dryrun

    changes = project.dryrun_resource("testmodule::Resource")
    assert changes == {"value": {'current': 'read', 'desired': 'write'}}

Options

The following options are available.

  • --venv: folder in which to place the virtual env for tests (will be shared by all tests), overrides INMANTA_TEST_ENV. This options depends on symlink support. This does not work on all windows versions. On windows 10 you need to run pytest in an admin shell.
  • --module_repo: location to download modules from, overrides INMANTA_MODULE_REPO. The default value is the inmanta github organisation.

Use the generic pytest options --log-cli-level to show Inmanta logger to see any setup or cleanup warnings. For example, --log-cli-level=INFO

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-inmanta-0.6.0.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file pytest-inmanta-0.6.0.tar.gz.

File metadata

  • Download URL: pytest-inmanta-0.6.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6

File hashes

Hashes for pytest-inmanta-0.6.0.tar.gz
Algorithm Hash digest
SHA256 6403198f269bea9fac0ca2b4bda077ffe64e53d3d75205ca64c416cf6786c1ee
MD5 9f041df6b0f40d4c7b7c90e2f6746e51
BLAKE2b-256 1bbdb6f7302cec355175580a3b0d0f758ac87d5a95596a86ab9040d1a22834b3

See more details on using hashes here.

Supported by

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