Skip to main content

Add your description here

Project description

Pytest plugin for jubilant.

Eases the transition from pytest-operator to jubilant. And some cool stuff on top.

Fixtures

juju

This is a model-scoped fixture that uses a temporary model and tears it down on context exit. Usage:

from jubilant import Juju, all_active

def test_deploy(juju: Juju):
    juju.deploy("./foo.charm", "foo")
    juju.wait(
        lambda status: all_active(status, "foo"),
        timeout=1000
    )

Pytest CLI options

--model

Target a specific, existing model instead of provisioning a fresh, temporary one. Do note that this model won't be torn down at the end of the test run. Usage:

juju add-model mymodel pytest ./tests/integration -k test_foo --model "mymodel"

--switch

Switch to the (randomly-named) model that is currently in scope, so you can keep an eye on the juju status as the tests progress. (Won't work well if you're running multiple test modules in parallel.)

pytest ./tests/integration --switch

--keep-models

Skip destroying the newly generated models when the tests are done. Usage:

pytest ./tests/integration --keep-models

--no-teardown

Skip all tests marked with teardown. Useful to inspect the state of a model after a (failed) test run. Implies --keep-models.

pytest ./tests/integration --no-teardown

--no-setup

Skip all tests marked with setup. Especially useful when re-running a test on an existing model which is already set-up, but not torn down. See this article for the idea behind this workflow. Usage:

pytest ./tests/integration --no-teardown # make a note of the temporary model name pytest ./tests/integration --model --no-setup

Markers

setup

Marker for tests that prepare (parts of) a model.

Usage:

import pytest

@pytest.mark.setup
def test_deploy(juju):
    juju.deploy("A")
    juju.deploy("B")

@pytest.mark.setup
def test_relate(juju):
    juju.integrate("A", "B")

teardown

Marker for tests that destroy (parts of) a model.

Usage:

import pytest

@pytest.mark.teardown
def test_disintegrate(juju):
    juju.remove_relation("A", "B")

@pytest.mark.teardown
def test_destroy(juju):
    juju.remove_application("A")
    juju.remove_application("B")

Utilities

pack_charm

Wrapper around charmcraft pack to build a charm and return the packed charm path and its resources, ready to be passed to juju.deploy.

from pytest_jubilant import pack_charm
import pytest

@pytest.mark.setup
def test_build_deploy_charm(juju):
    out = pack_charm("/path/to/foo-charm-repo-root-dir/")
    juju.deploy(
        out.charm,
        "foo",
        # the resources can only be inferred from the charm's metadata/charmcraft yaml 
        # if you use the `upstream-source` convention
        resources=out.resources,
        num_units=3,
    )
# example /path/to/foo-charm-repo-root-dir/charmcraft.yaml

# [snip] 
resources:
  nginx-image:
    type: oci-image
    description: OCI image for nginx
    upstream-source: ubuntu/nginx:1.24-24.04_beta
  nginx-prometheus-exporter-image:
    type: oci-image
    description: OCI image for nginx-prometheus-exporter
    upstream-source: nginx/nginx-prometheus-exporter:1.1.0

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_jubilant-0.2.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_jubilant-0.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_jubilant-0.2.tar.gz.

File metadata

  • Download URL: pytest_jubilant-0.2.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytest_jubilant-0.2.tar.gz
Algorithm Hash digest
SHA256 efabdc6bdaaaf110870173d016dff492433c91c16f06054b7c10dc0b7e2dad30
MD5 eeaf62392034f969435ffdca56a9a14b
BLAKE2b-256 4c7f547e655d982e75a81dfb8c61cdb429ba7b249ad9deaaf1b9c4d47e497155

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_jubilant-0.2.tar.gz:

Publisher: build-and-publish.yaml on canonical/pytest-jubilant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_jubilant-0.2-py3-none-any.whl.

File metadata

  • Download URL: pytest_jubilant-0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytest_jubilant-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6701485f1fa266e2da94b96054266a6c59b1f7adf1155580ba83e1bb099d3381
MD5 4ddfd9156132413b3c4b4e7353d3fcb6
BLAKE2b-256 a59a0eabcc89209b5b006bc5fc22756fdce1ad254ddb4214b519f137c246409f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_jubilant-0.2-py3-none-any.whl:

Publisher: build-and-publish.yaml on canonical/pytest-jubilant

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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