Skip to main content

Fixtures for Operators

Project description

pytest-operator

PyTest plugin to make it easy to create integration tests for Operator Charms.

Usage

Include pytest-operator in the deps of your tox.ini file:

[testenv]
deps =
  pytest
  pytest-operator

Then, just start using the ops_test fixture in your async tests. This module-scoped fixture provides a libjuju Model, helpers to build charms for testing, and the ability to abort testing so that the remaining tests in the module are automatically xfailed (you can also mark a test so that this happens automatically if the test fails; this is typically used on the initial deployment test, where subsequent tests depend on the deployment having succeeded).

As an additional nicety, you don't have to explicitly mark an async test with @pytest.mark.asyncio; if it's a test function / method and it's async, it will be marked automatically.

Example:

import pytest


@pytest.mark.abort_on_fail
async def test_build_and_deploy(ops_test):
    my_charm = await ops_test.build_charm(".")
    await ops_test.model.deploy(my_charm)
    await ops_test.model.wait_for_idle()


async def test_status(ops_test):
    assert ops_test.model.applications["my-charm"].units[0].workload_status == "active"

Reference

More details can be found in the reference docs.

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-operator-0.8.3.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

pytest_operator-0.8.3-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-operator-0.8.3.tar.gz.

File metadata

  • Download URL: pytest-operator-0.8.3.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for pytest-operator-0.8.3.tar.gz
Algorithm Hash digest
SHA256 8a7fa2c093744cfede473123741181cf36e759d9660eacb86bdb3d736b266dc5
MD5 c4f86f117ad71e7f0a81c6b2f2270ba7
BLAKE2b-256 786a2caf17e289ab8cab228c3491589632b67226964b519ddf57e8d467dfe61d

See more details on using hashes here.

File details

Details for the file pytest_operator-0.8.3-py3-none-any.whl.

File metadata

  • Download URL: pytest_operator-0.8.3-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for pytest_operator-0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ece53c4c262dcfd081f06af0df132fbf2b96f66f0019bd80fcbd72c0e0b4aefd
MD5 012e69f37f62a1140fecb9d8579c07f2
BLAKE2b-256 f9e6a9af4e668d1bc82d3225bfb583b4bcea0632c946eaeed4b2b2c30314a3fa

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