Skip to main content

Juju CLI wrapper for charm integration testing

Project description

Jubilant, the joyful library for integration-testing Juju charms

Jubilant is a Python library that wraps the Juju CLI for use in charm integration tests. It provides methods that map 1:1 to Juju CLI commands, but with a type-annotated, Pythonic interface.

You should consider switching to Jubilant if your integration tests currently use pytest-operator (and they probably do). Jubilant has an API you'll pick up quickly, and it avoids some of the pain points of python-libjuju, such as websocket failures and having to use async. Read our design goals.

Jubilant is currently in pre-release or "beta" phase (see PyPI releases). Our intention is to release version 1.0.0 in May 2025.

Read the full documentation

Using Jubilant

Jubilant is published to PyPI, so you can install and use it with your favorite Python package manager:

$ pip install jubilant
# or
$ uv add jubilant

Because Jubilant calls the Juju CLI, you'll also need to install Juju.

To use Jubilant in Python code:

import jubilant

juju = jubilant.Juju()
juju.deploy('snappass-test')
juju.wait(jubilant.all_active)

Below is an example of a charm integration test. First we define a module-scoped pytest fixture named juju which creates a temporary model and runs the test with a Juju instance pointing at that model. Jubilant'stemp_model context manager creates the model during test setup and destroys it during teardown:

# conftest.py
@pytest.fixture(scope='module')
def juju():
    with jubilant.temp_model() as juju:
        yield juju


# test_deploy.py
def test_deploy(juju: jubilant.Juju):        # Use the "juju" fixture
    juju.deploy('snappass-test')             # Deploy the charm
    status = juju.wait(jubilant.all_active)  # Wait till the app and unit are 'active'

    # Hit the Snappass HTTP endpoint to ensure it's up and running.
    address = status.apps['snappass-test'].units['snappass-test/0'].address
    response = requests.get(f'http://{address}:5000/', timeout=10)
    response.raise_for_status()
    assert 'snappass' in response.text.lower()

You don't have to use pytest with Jubilant, but it's what we recommend. Pytest's assert-based approach is a straight-forward way to write tests, and its fixtures are helpful for structuring setup and teardown.

Contributing and developing

Anyone can contribute to Jubilant. It's best to start by opening an issue with a clear description of the problem or feature request, but you can also open a pull request directly.

Jubilant uses uv to manage Python dependencies and tools, so you'll need to install uv to work on the library. You'll also need make to run local development tasks (but you probably have make installed already).

After that, clone the Jubilant codebase and use make all to run various checks and the unit tests:

$ git clone https://github.com/canonical/jubilant
Cloning into 'jubilant'...
...
$ cd jubilant
$ make all
...
========== 107 passed in 0.26s ==========

To contribute a code change, write your fix or feature, add tests and docs, then run make all before you push and create a PR. Once you create a PR, GitHub will also run the integration tests, which takes several minutes.

Doing a release

To create a new release of Jubilant:

  1. Update the __version__ field in jubilant/__init__.py to the new version you want to release.
  2. Push up a PR with this change and get it reviewed and merged.
  3. Create a new release on GitHub with good release notes. The tag should start with a v, like v1.2.3. Once you've created the release, the publish.yaml workflow will automatically publish it to PyPI.
  4. Once the publish workflow has finished, check that the new version appears in the PyPI version history.

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

jubilant-0.4.1.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

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

jubilant-0.4.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file jubilant-0.4.1.tar.gz.

File metadata

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

File hashes

Hashes for jubilant-0.4.1.tar.gz
Algorithm Hash digest
SHA256 0acec84d6ebe48f305bf3acc484347fb2c25e9aa7451019f7a44893f95c93779
MD5 b2e69787f21c19dc0f1c6b17991b05c3
BLAKE2b-256 2cf141362d3bfb5c2c44f9bdf9a900e5899f3b9da40fa6e7b88be821dd619e27

See more details on using hashes here.

Provenance

The following attestation bundles were made for jubilant-0.4.1.tar.gz:

Publisher: publish.yaml on canonical/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 jubilant-0.4.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for jubilant-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3fa4bd4bd9de28e41c81010ea0fc1cc3be98be744149a71fd906a613ea177ea
MD5 50bdde98dd7da8d54b113498d0d0e8ca
BLAKE2b-256 8ec1c2cc03d2c0420353659388f3e646a09ea54c27357d79c6bf528bf71793ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for jubilant-0.4.1-py3-none-any.whl:

Publisher: publish.yaml on canonical/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